2013-07-18 43 views
1

我有嵌入在滚动视图UICollectionView单元格的中心点:see picture获取滚动内嵌视图

每个白方块是一家集视图单元格。用户可以水平滚动显示其他单元格。

当用户点击一个单元格时,我创建了一个动画,导致该单元格从它自己的中心向外扩展,并向新的视图控制器转换。

下面是代码:

//cell is selected: 

//grab snapshot of cell 
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; 
UIImage *cellImage = [self imageOfCollectionCell:cell]; 

//hold the snapshot in this dict  
NSMutableDictionary *cellImageDict = [[NSMutableDictionary alloc]init]; 
[cellImageDict setObject:cellImage forKey:SELECTED_INBOX_EMAIL_IMAGE]; 
[ViewControllerSnapShotDictionary sharedInstance].vcdict = nil; 
[ViewControllerSnapShotDictionary sharedInstance].vcdict = cellImageDict; 

//get the center of the cell (HERE IS WHERE THE PROBLEM IS) 
CGPoint cellCenter = CGPointMake(cell.center.x, cell.center.y); 

//do the animation using the snapshot and cell center 
[self startPinchingOutCellFromCenterPoint:cellCenter forTransitionTo:emailController withSnapShotImage:SELECTED_INBOX_EMAIL_IMAGE]; 

的代码工作正常,但如果集合视图已滚动。动画要求我知道单元格的中心在屏幕上的哪个位置,触摸的位置以及相对于我正在查看的视图的坐标的位置。然而

cell.center.x = 490 
cell.center.y = 374 

,如果我做滚动到:

例如,如果集合看法并没有被滚动,而我选择了上述图像的中心单元,该中心还不如回右,然后选择新的中心单元,我可能会得到这样的:

cell.center.x = 1770 
cell.center.y = 374 

我的问题是,是否有任何更好的方法来完成我想做的事,或者是有一种方式来获得它位于细胞中心的一个手柄在self.view中的当前位置?

回答

3

我认为这是因为中心坐标位于collectionView的坐标系(滚动)。您需要将其转换为不滚动的坐标系。

尝试这样:

CGPoint realCenter = [collectionView convertPoint:cell.center 
            toView:collectionView.superview]; 

它能做什么,基本上是将来自的CollectionView的坐标系的中心,它的父应该是固定的(不滚动)。

,你甚至可以通过传递零作为参数,获取屏幕(窗口)的坐标:

CGPoint realCenter = [collectionView convertPoint:cell.center 
            toView:nil]; 

它是由你来决定哪个坐标要转换。