Ios layoutAttributesForItemAtIndexPath不';t执行窥视和弹出时返回实际位置
我正在尝试使用以下代码实现Peek和Pop来预览照片库中的图像: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
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!)