How to find a UICollectionViewCell's coordinates relative to the App Window

后端 未结 3 673
感动是毒
感动是毒 2021-02-08 10:37

Is it possible to translate a UICollectionViewCell\'s coordinates from being relative to the UICollectionView to being relative to the superview<

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 11:16

    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];
    

    with

    CGRect frame = [collectionView convertRect:cell.frame toView:self.view];
    

    The problem was that you were calling the convert method on the cell, not the collectionView.

提交回复
热议问题