这就是我执行转换的方式:
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
}
}