如何找到相对于应用程序窗口的UICollectionViewCell的坐标 [英] How to find a UICollectionViewCell's coordinates relative to the App Window
问题描述
是否可以将UICollectionViewCell's
坐标从相对于UICollectionView
的坐标转换为相对于superview
的坐标?到目前为止,触摸到superview
时,我一直无法转换UICollectionViewCell's
坐标.到目前为止,这是我尝试过的事情:
Is it possible to translate a UICollectionViewCell's
coordinates from being relative to the UICollectionView
to being relative to the superview
? So far I've been unable to translate a UICollectionViewCell's
coordinates when touched to the superview
. Here's what I've tried so far:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell"
forIndexPath:indexPath];
CGRect frame = CGRectMake(0.0,
0.0,
cell.frame.size.width,
cell.frame.size.height);
frame.origin = [cell convertPoint:cell.frame.origin
toView:self.view];
}
我想创建一个新的框架,该框架起源于单元格在视图中的位置,而不是在UICollectionView
中.任何帮助将非常感谢.
I'd like to create a new frame which originates from the cell's position on the view, not in the UICollectionView
. Any help would be great thanks.
推荐答案
这个答案很晚了,但希望对您有所帮助. 丹,您有正确的想法,但是拥有您的想法要容易得多.只需替换
This answer is very late, but hopefully it will help someone. Dan, you have the right idea, but it is even easier that what you have. Just replace
CGRect frame = CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height);
frame.origin = [cell convertPoint:cell.frame.origin toView:self.view];
使用
CGRect frame = [collectionView convertRect:cell.frame toView:self.view];
问题是您在单元格而不是collectionView上调用了convert方法.
The problem was that you were calling the convert method on the cell, not the collectionView.
这篇关于如何找到相对于应用程序窗口的UICollectionViewCell的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!