我有表格视图的一些内容项列表,以及每个项目的选项控制器。 我在3D触摸上使用此选项控制器或为旧设备长按。 我已经以非常基本的方式实现了它:
extension ViewController {
func checkForForceTouch() {
if #available(iOS 9.0, *) {
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: tableView)
} else {
addLongPressRecognizer()
}
} else {
addLongPressRecognizer()
}
}
...
}
@available(iOS 9.0, *)
extension ViewController: UIViewControllerPreviewingDelegate {
public func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
if let indexPath = tableView.indexPathForRow(at: location) {
let cell = tableView.cellForRow(at: indexPath)!
previewingContext.sourceRect = cell.frame
return self.optionsController(for: indexPath)
} else {
return nil
}
}
public func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
viewControllerToCommit.modalPresentationStyle = .overFullScreen
present(viewControllerToCommit, animated: true, completion: nil)
}
}
一切正常,除了一件事:在3d触摸选项的情况下,控制器显示在窥视视图中。我想立即呈现它,就像Apple Music应用程序一样。有办法吗?