gpt4 book ai didi

swift - UIViewControllerPreviewing peek 不显示我的预览

转载 作者:行者123 更新时间:2023-11-28 07:58:50 24 4
gpt4 key购买 nike

我在使用 UIViewControllerPreviewing API 时遇到问题。它在以前版本的应用程序(iOS?)中运行良好,但我只是注意到它在当前版本中不再运行。

我没有针对此进行任何更改(只是迁移到 Swift 4 和此类更改),但整个应用程序都在发生这种情况(不仅仅是下面的示例),代表 4-5 不同 强制触摸 peeks 和 pops。

当我用力触摸我的 Collection View 上的一个单元格时,这就是我所看到的。发生模糊但我的预览 View Controller 没有出现。 What I see when force touching

请注意,弹出窗口工作正常,我的 View Controller (配置良好)被推送到导航堆栈上。

我尝试使用 Xcode 中的 UI 调试器,我的预览 View Controller 的 View 似乎没有指定大小,这很奇怪。 enter image description here

这是我的代码:

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)

我很乐意收到有关尝试的建议,或者如果您已经在您的应用中解决了这个问题,我会很高兴收到解决方案。

谢谢!

最佳答案

也许代替:

previewingContext.sourceRect = viewRectInCollectionView

尝试:

previewingContext.sourceRect = cell.frame

我在使用 collectionView.convert() 时遇到了类似的问题。

关于swift - UIViewControllerPreviewing peek 不显示我的预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47216159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com