我对UIViewControllerPreviewing API有一个问题。它在应用程序的早期版本(iOS?)中运行良好,但我只是注意到,它在当前版本中已经不再工作了。
我没有改变任何具体的(刚刚迁移到Swift 4和类似的变化),但这正在发生在整个应用程序(不仅仅是下面的例子),代表4-5不同的力量触摸窥视和弹出。
当我强行触摸集合视图上的一个单元格时,这里是我看到的。模糊会发生,但我的预览视图控制器不会出现。

注意,pop工作正常,我的视图控制器(配置良好)被推送到导航堆栈上。
我尝试使用Xcode中的UI调试器,而且我的预览视图控制器的视图似乎没有给定大小,奇怪。

这是我的代码:
extension HomeViewController: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = collectionView.indexPathForItem(at: location), let cell = collectionView.cellForItem(at: indexPath) as? MyCell else {
return nil
}
// Configure previewing context
let viewRectInCollectionView = collectionView.convert(cell.frame, from: coverImageView.superview!)
previewingContext.sourceRect = viewRectInCollectionView
// Generate cover view
let viewController = MyViewController(/* some parameters */)
return viewController
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
navigationController?.pushViewController(viewControllerToCommit, animated: true)
}
}我也尝试给出一个首选的内容大小,但是它没有改变任何东西:
viewController.preferredContentSize = CGSize(width: 300.0, height: 300.0)
// or
viewController.preferredContentSize = CGSize(width: 0.0, height: 300.0)我很乐意收到一些建议来尝试,或者如果你已经在你的应用程序中解决了这个问题。
谢谢!
发布于 2017-11-28 10:55:14
也许不是:
previewingContext.sourceRect = viewRectInCollectionView
尝试:
previewingContext.sourceRect = cell.frame。
我在使用collectionView.convert()时也遇到了类似的问题。
https://stackoverflow.com/questions/47216159
复制相似问题