1. 禁止模态弹出下滑返回
if (@available(iOS 13.0, *)) {
UIViewController.modalInPresentation = YES;
}
2. 获取模态弹出下滑返回
2.1 设置presentationController.delegate
let yourVC = YourViewController()
yourVC.preferredContentSize = CGSize.init(width: 540, height: 580)
let nav = UINavigationController.init(rootViewController: yourVC)
nav.modalPresentationStyle = .formSheet
nav.presentationController?.delegate = yourVC
self.present(nav, animated: true) {}
2.2 继承UIAdaptivePresentationControllerDelegate
class YourViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
//MARK: - UIAdaptivePresentationControllerDelegate
/// 模态弹出下滑消失
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
在这里可以做操作
}
}
3. 代码简介
3.1 presentationController是什么?
显示控制器:管理当前view controller的显示控制器。
如果view controller由presentationController管理,则此属性包含该对象。如果view controller的不由presentationController管理,则此属性为nil。
如果尚未显示当前view controller,则访问此属性将基于modalPresentationStyle属性中的当前值创建一个presentationController。
所以上面代码,在拿到NavigationController的presentationController后,将代理设置给展示用的ViewController。
参考资料:UIPresentationController简介
UIPresentationController(官方简介翻译)
网友评论