在iOS 13之前,提供了用于覆盖整个屏幕的视图控制器。并且,在关闭后,将viewDidAppear执行父视图控制器功能。
现在,iOS 13默认将表单显示为视图控制器,这意味着卡将部分覆盖基础视图控制器,这意味着viewDidAppear不会被调用,因为父视图控制器从未真正消失过。
有没有一种方法可以检测到所显示的视图控制器工作表已被解雇?我可以在父视图控制器中重写某些其他功能,而不是使用某种委托?
我正在为 iOS 13 的新“卡片式”模式视图更新我的应用程序。使用UIAdaptivePresentationControllerDelegate'spresentationControllerDidAttemptToDismiss()和presentationControllerDidDismiss()函数,一切都运行良好。但是,对于他们的意见.modalPresentationStyle设置为.popover,presentationControllerDidDismiss()在紧凑的环境中(如分离式或滑盖通过电话或iPad)被提出时,不叫。在常规尺寸类环境(例如 iPad 全屏)中呈现时,它会被正确调用。
我的代码设置非常简单:
呈现弹出框的代码:
func showChooser() {
// other setup code...
navController.modalPresentationStyle = .popover
navController.popoverPresentationController?.barButtonItem = self.viewController?.navigationItem.leftBarButtonItem
self.present(navController, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
然后,呈现的控制器符合UIAdaptivePresentationControllerDelegate并设置:
// This is in the presented view controller (i.e. the popover)
override func viewDidLoad() {
// other setup removed for brevity…
self.navigationController?.presentationController?.delegate = self
}
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
print("did dismiss")
self.cancel?()
}
Run Code Online (Sandbox Code Playgroud)
当视图在常规大小类环境中呈现时,它会正确显示为弹出框。当用户在弹出框外点击时, thenpresentationControllerDidDismiss()被调用。但是,当相同的代码出现在紧凑的环境中时,它会正确显示(作为卡片样式),但是当用户向下拖动视图时,presentationControllerDidDismiss()不会被调用。 …