'Interactive Delegate Methods Never Called
I want to make an interactive transition between a ViewController (1) and a NavigationViewController (2).
The NavigationController is called by a button, so there's no interactive transition when presenting. It can be dismissed by a button or a UIPanGestureRecognizer, so it can be dismissed interactively or not.
I have an object named TransitionManager for the transition, subclass of UIPercentDrivenInteractiveTransition.
The problem with the code below is that the two delegate methods interactionControllerFor... are never called.
Moreover, when I press the buttons or swip (UIPanGestureRecognizer), the basic animation of the modal segue is done. So the two 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?) {
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 triggered a modal segue to presenting the NavigationController
The NavigationController's delegate outlet is linked to an object of the TransitionManager class
The NavigationController is referenced in the TransitionManager class by the property "navigationController"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
