我试图在TableViewController
中实现Peek和Pop功能,这样当我3DTouch任何单元格时,它会向我显示SFSafariViewController
他们的预览{&#39}。我带我去点击它们。窥视功能工作得很好,但一旦它移动到弹出状态,它就不会在desired state中给出SFSafariViewController
,而是最终显示上一个视图中的导航控制器,以及显示SFViewController
(Image Here)。
这就是我在TableViewController
内编写偷看和弹出功能的方法:
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
}
}
答案 0 :(得分:1)
想出来。所以在下面的代码中:
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)
}