Delegate methods are not called (transitioningDelegate)

I am trying to implement a custom transition between two viewControllers. ( Swift 3.0 )

Between my two view controllers there is UISeguewith type show( animated = true).

So, I set the delegate methods UIViewControllerTransitioningDelegatein the extension of my first view controller:

extension DocumentsViewController : UIViewControllerTransitioningDelegate { ... }

And I also performed the necessary methods according to the protocol:

animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
     ...
}

public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
     ...
}

Now that it is done segue, in firstViewControllerI use the delegate method prepareForSegueto finally set transitioningDelegatein my `secondViewController, see below:

public override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    super.prepare(for: segue, sender: sender)
    if let destination = segue.destination as? DocumentDetailViewController {
        destination.transitioningDelegate = self
    }
}

, firstViewController. transitioningDelegate firstViewController , .

?

PS: segue have Animated to true, , .

.

:. MadreDeDios, Matt Tushar.

1: , viewController UINavigationControllerDelegate UIViewControllerTransitioningDelegate. (. MadreDeDios).

2: :

public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

...

}

3: viewDidLoad() firstViewController (. ):

override public func viewDidLoad() {
    super.viewDidLoad()
    //...
    self.navigationController?.delegate = self
}

4: push segue secondViewController (. Tushar).

, .

+5
3

, transitioningDelegate. . . .

+5

push-, , .

UINavigationController, , .

. , , :

extension MyNavigationController: UINavigationControllerDelegate {

     func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        //Check for the good animation
        return MyAnimation()
    }
}

MyNavigationController

override func viewDidLoad() {
    super.viewDidLoad()

    //This is the key
    self.delegate = self

    //Only if you want to animate the presentation of your navigation controller itself, the first time it appears:
    self.transitioningDelegate = self
}
+5

Try to remove the transition from the storyboard and execute the view code manually and explicitly specify "true" for the animated parameter:

presentViewController (documentVC, animated: true, completion: zero)

+1
source

Source: https://habr.com/ru/post/1656821/


All Articles