当前,我在viewDidLoad
中具有以下代码:
if #available(iOS 9.0, *) {
if traitCollection.forceTouchCapability == .Available {
registerForPreviewingWithDelegate(self, sourceView: tableView)
}
}
重点是,在这种情况下,模糊的是UITableView
中的所有内容,而不是特定的UITableViewCell
中的所有内容。
如何只暴露一个细胞?
这应该在viewDidLoad()
中:
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: tableView)
}
然后在previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint)
中添加此:
guard let selectedIndexPath = tableView.indexPathForRow(at: location) else { return nil }
previewingContext.sourceRect = tableView.rectForRow(at: selectedIndexPath)
您做对了,您确实需要在viewDidLoad
中注册预览。虽然,您还需要实现previewingContext
方法,以提供源rect。基本上,您将单元作为源矩形,其外部的所有内容都将变得模糊。
请查看此Peek and Pop tutorial了解更多详细信息。
您也可以结帐the sample of code