Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios layoutAttributesForItemAtIndexPath不';t执行窥视和弹出时返回实际位置_Ios_Iphone_3dtouch - Fatal编程技术网

Ios layoutAttributesForItemAtIndexPath不';t执行窥视和弹出时返回实际位置

Ios layoutAttributesForItemAtIndexPath不';t执行窥视和弹出时返回实际位置,ios,iphone,3dtouch,Ios,Iphone,3dtouch,我正在尝试使用以下代码实现Peek和Pop来预览照片库中的图像: func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { if let indexPath = self.collectionView!.indexPathForItemAtPoint(location

我正在尝试使用以下代码实现Peek和Pop来预览照片库中的图像:

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
    if let indexPath = self.collectionView!.indexPathForItemAtPoint(location), cellAttributes = self.collectionView!.layoutAttributesForItemAtIndexPath(indexPath) {

        previewingContext.sourceRect = cellAttributes.frame
    }

    let selectedPhotoAsset = self.allPhotos[self.selectedPhotoIndexPath![0].item] as! PHAsset

    guard let displayImageDetailVC = storyboard?.instantiateViewControllerWithIdentifier("DisplayImageDetailVC") as? DisplayImageViewController else {
        print("Error instantiate DisplayImageDetail View Controller")
        return nil
    }

    displayImageDetailVC.selectedPhotoAsset = selectedPhotoAsset

    return displayImageDetailVC
}
尽管它可以工作,但问题是在集合视图滚动后,预览区域有时在尝试偷看时不在单元格的确切位置。


有什么方法可以得到单元格的实际位置吗?

我已经找到了这个问题的解决方案,结果它与RegisterForReviewingWithDelegate有关

而不是

registerForPreviewingWithDelegate(self, sourceView: view)
应该是

registerForPreviewingWithDelegate(self, sourceView: self.collectionView!)