ios - How to access my custom UIPresentationController from within presented controller? -
this how perform transitioning:
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) } }
and within presented controller (alertvc
) @ point need access presentation controller:
print(presentationcontroller as? overlaypresentationcontroller) //nil print(presentationcontroller) //is ok, uipresentationcontroller
why?
presenting:
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 } }
you view controller presenting current view controller calling presentingviewcontroller
// view controller presented view controller (or farthest ancestor.) self.presentingviewcontroller
if presenting view controller in navigation controller returns uinavigationcontroller. can view controller need so:
let presentingnvc = self.presentingviewcontroller as? uinavigationviewcontroller let neededvc = presentingnvc.viewcontrollers.last as? neededviewcontroller
Comments
Post a Comment