ios - Interactive Delegate Methods Never Called -



ios - Interactive Delegate Methods Never Called -

i want create interactive transition between viewcontroller (1) , navigationviewcontroller (2).

the navigationcontroller called button, there's no interactive transition when presenting. can dismissed button or uipangesturerecognizer, can dismissed interactively or not.

i have object named transitionmanager transition, subclass of uipercentdriveninteractivetransition.

the problem code below 2 delegate methods interactioncontrollerfor... never called.

moreover, when press buttons or swip (uipangesturerecognizer), basic animation of modal segue done. 2 delegate methods animationcontrollerfor... don't work either.

any ideas ? thanks

viewcontroller.swift let transitionmanager = transitionmanager() override func viewdidload() { super.viewdidload() self.transitioningdelegate = transitionmanager } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { allow dest = segue.destinationviewcontroller uiviewcontroller dest.transitioningdelegate = transitionmanager dest.modalpresentationstyle = .custom } transitionmanager.swift class transitionpushmanager: uipercentdriveninteractivetransition, uinavigationcontrollerdelegate, uiviewcontrollertransitioningdelegate { @iboutlet var navigationcontroller: uinavigationcontroller! var animation : animator! // implement uiviewcontrolleranimatedtransitioning protocol override func awakefromnib() { var pangesture = uipangesturerecognizer(target: self, action: "gesturehandler:") navigationcontroller.view.addgesturerecognizer(pangesture) animation = animator() } func gesturehandler(pan : uipangesturerecognizer) { switch pan.state { case .began : interactive = true navigationcontroller.presentingviewcontroller?.dismissviewcontrolleranimated(true, completion:nil) case .changed : ... default : ... interactive = false } } func animationcontrollerforpresentedcontroller(presented: uiviewcontroller, presentingcontroller presenting: uiviewcontroller, sourcecontroller source: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? { homecoming animation } func animationcontrollerfordismissedcontroller(dismissed: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? { homecoming animation } func interactioncontrollerforpresentation(animator: uiviewcontrolleranimatedtransitioning) -> uiviewcontrollerinteractivetransitioning? { homecoming nil } func interactioncontrollerfordismissal(animator: uiviewcontrolleranimatedtransitioning) -> uiviewcontrollerinteractivetransitioning? { homecoming self.interactive ? self : nil } main.storyboard

the button on viewcontroller triggered modal segue presenting navigationcontroller

the navigationcontroller's delegate outlet linked object of transitionmanager class

the navigationcontroller referenced in transitionmanager class property "navigationcontroller"

the notion of root view controller instantiating transitionmanager / transitionpushmanager used navigation controller's animation , interaction controllers doesn't seem right. doesn't seem right transition manager uipercentdriveninteractivetransition subclass (as opposed beingness generic manager object mill animation , interaction controllers). don't see how transition manager setting @iboutlet navigation controller, either, perhaps that's been omitted here. (i worry outlet strong.)

while i'm sure track downwards current model going wrong , prepare it, confess view controller hierarchy , overall object model doesn't sense quite right. i'd rather implement in more logical view hierarchy , object ownership model.

let's imagine root scene ("root") presents navigation controller scene ("nav"), pushes scene b c, example, i'd imagine object model this, navigation controller own own animation controller, interaction controller, , gesture recognizer:

this need when considering (a) custom transition (non-interactive) when "root" presents "nav"; , (b) custom transition (interactive or not) when "nav" dismisses in order homecoming "root". so, i'd subclass navigation controller which:

adds gesture recognizer view;

sets transitioningdelegate yield custom animation transition root scene navigation controller scene (and back):

the transitioningdelegate homecoming interaction controller (which exist while gesture recognizer in progress), yielding interactive transition during gesture , non-interactive transition if dismiss outside of context of gesture.

that looks like:

class customnavigationcontroller: uinavigationcontroller, uiviewcontrollertransitioningdelegate { override func viewdidload() { super.viewdidload() self.transitioningdelegate = self allow pan = uiscreenedgepangesturerecognizer(target: self, action: "handlepan:") pan.edges = .left self.view.addgesturerecognizer(pan); } var interactioncontroller: uipercentdriveninteractivetransition! func handlepan(gesture: uiscreenedgepangesturerecognizer) { allow percent = gesture.translationinview(gesture.view!).x / gesture.view!.bounds.size.width if gesture.state == .began { interactioncontroller = uipercentdriveninteractivetransition() dismissviewcontrolleranimated(true, completion: nil) } else if gesture.state == .changed { interactioncontroller.updateinteractivetransition(percent) } else if gesture.state == .ended { if percent > 0.5 { interactioncontroller.finishinteractivetransition() } else { interactioncontroller.cancelinteractivetransition() } interactioncontroller = nil } } func animationcontrollerforpresentedcontroller(presented: uiviewcontroller, presentingcontroller presenting: uiviewcontroller, sourcecontroller source: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? { homecoming youranimatorhere() } func animationcontrollerfordismissedcontroller(dismissed: uiviewcontroller) -> uiviewcontrolleranimatedtransitioning? { homecoming youranimatorhere() } func interactioncontrollerforpresentation(animator: uiviewcontrolleranimatedtransitioning) -> uiviewcontrollerinteractivetransitioning? { homecoming nil } func interactioncontrollerfordismissal(animator: uiviewcontrolleranimatedtransitioning) -> uiviewcontrollerinteractivetransitioning? { homecoming interactioncontroller } }

so, can alter base of operations class of navigation controller in storyboard custom subclass, , root scene can nowadays navigation controller (with no special prepareforsegue) , works.

clearly, when want interactive transition presenting 1 scene another, takes little tweak model (i have source controller own interaction

ios swift delegates transition interactive

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -