I want to make an interactive transition between ViewController (1) and NavigationViewController (2).
The navigation controller is called by the button, so there is no interactive transition when presenting. It can be rejected with the button or UIPanGestureRecognizer, so it can be rejected interactively or not.
I have a TransitionManager object to navigate to, a subclass of UIPercentDrivenInteractiveTransition.
The problem with the code below is that the two delegate methods of interactionControllerFor... never called.
In addition, when I press buttons or switch (UIPanGestureRecognizer), the main animation of the modal segment is executed. Thus, both animationControllerFor... delegate methods do not 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?) { let dest = segue.destinationViewController as 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? { return animation } func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return animation } func interactionControllerForPresentation(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return nil } func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return self.interactive ? self : nil }
Main.storyboard
The button on the ViewController caused a modal transition to the NavigationController view.
The NavigationController delegate output is associated with a TransitionManager class object
The NavigationController pointer in the TransitionManager class refers to the "navigationController" property
source share