gpt4 book ai didi

ios - 3DTouch 上的 SFSafariViewController 问题(弹出状态)

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

我正在尝试在 TableViewController 中实现 Peek 和 Pop 功能,这样当我 3DTouch 任何单元格时,它都会显示 SFSafariViewController 的预览他们会带我去敲他们。 peek 功能工作得很好,但一旦它进入弹出状态,它就不会在 desired state 中提供 SFSafariViewController但最终显示的是前一个 View 中的导航 Controller ,以及一个显示 SFViewController (Image Here) 的尺寸不佳的 View .

这就是我在 TableViewController 中编写 peek 和 pop 功能的方式:

extension MyBlogsTableViewController: UIViewControllerPreviewingDelegate {

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
if let indexPath = tableView.indexPathForRowAtPoint(location) {

let cell = tableView.cellForRowAtIndexPath(indexPath) as! MyBlogsTableViewCell

let destinationViewController = SFViewControllerToExplore(indexPath.row)
destinationViewController.preferredContentSize = CGSize(width: 0.0, height: 0.0)

previewingContext.sourceRect = cell.frame

return destinationViewController
}
return nil
}

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
navigationController?.pushViewController(viewControllerToCommit, animated: true)
}

private func touchedView(view: UIView, location: CGPoint) -> Bool {
let locationInView = view.convertPoint(location, fromView: tableView)
return CGRectContainsPoint(view.bounds, locationInView)
}

private func SFViewControllerToExplore(index: Int) -> UIViewController {
var destinationController: SFSafariViewController

destinationController = SFSafariViewController(URL: NSURL(string: identifierOfLinks[index])!, entersReaderIfAvailable: true)

return destinationController
}

}

最佳答案

想通了。所以在下面的代码中:

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
navigationController?.pushViewController(viewControllerToCommit, animated: true)
}

我实际上不应该使用 pushViewController,我应该使用 presentViewController

更正后的代码:

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
navigationController?.presentViewController(viewControllerToCommit, animated: true, completion: nil)
}

关于ios - 3DTouch 上的 SFSafariViewController 问题(弹出状态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36736108/

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