美文网首页
iOS开发-获取模态弹出下滑返回

iOS开发-获取模态弹出下滑返回

作者: 左方 | 来源:发表于2021-10-11 16:53 被阅读0次

1. 禁止模态弹出下滑返回

如何禁止iOS13新特性:模态弹出下滑返回

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(官方简介翻译)

相关文章

网友评论

      本文标题:iOS开发-获取模态弹出下滑返回

      本文链接:https://www.haomeiwen.com/subject/rynloltx.html