這是我如何執行過渡:如何從提供的控制器中訪問我的自定義UIPresentationController?
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的屬性。它擁有演示文稿的視圖層次結構並呈現控制器 –
聽起來很有希望...可以通過這種方式訪問我的演示文稿控制器嗎? –
對不起,我不知道,我已經通過互聯網閱讀,所以我與你分享,你可以嘗試如果作品,那麼你的很多時間將被保存。祝你好運 –