【发布时间】:2018-01-01 13:13:42
【问题描述】:
这就是我执行转换的方式:
extension UIViewController: UIViewControllerTransitioningDelegate {
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return OverlayPresentationController(presentedViewController: presented, presenting: presenting)
}
func presentOverlayController(_ controller: UIViewController) {
controller.modalPresentationStyle = .custom
controller.transitioningDelegate = self
present(controller, animated: true)
}
}
然后在我呈现的控制器 (AlertVC) 中,有时我需要访问它的呈现控制器:
print(presentationController as? OverlayPresentationController) //nil
print(presentationController) //is ok, UIPresentationController
为什么?
介绍:
let controller = AlertVC.instantiate()
controller.update()
presentOverlayController(controller)
class AlertVC: UIViewController {
class func instantiate() -> AlertVC {
return UIStoryboard(name: "Alert", bundle: Bundle(for: LoginVC.classForCoder())).instantiateInitialViewController() as! AlertVC
}
func update() {
_ = view
print(presentationController as? OverlayPresentationController) //nil
}
}
【问题讨论】:
-
UIPresentationController 有一个名为 containerView 的属性。它保存了展示和展示的控制器的视图层次结构
-
听起来很有希望...可以通过这种方式访问我的演示控制器吗?
-
对不起,我不知道,我已经通过互联网阅读了它,所以我与您分享,您可以尝试如果有效,那么您的大量时间将被节省。祝你好运
标签: ios swift uipresentationcontroller