Hero: Different animation for push and pop using Navigation Controller.

Created on 14 Dec 2017  路  4Comments  路  Source: HeroTransitions/Hero

Hi! I am using this library with default animation. I only set the parameters isHeroEnabled and heroID.
Everything is ok, but I need to do a different animation for "pop" transition. How can I do?
Thank you for your help!

confirmed bug discussion

Most helpful comment

you should set your UINavigationControllerDelegate to something that will return a custom HeroTransition navigation delegate.

1. define your transition

fileprivate let heroTransition = HeroTransition()

2. set your navigation controller's delegate

self.navigationController?.delegate = self
self.navigationController?.heroNavigationAnimationType = .autoReverse(presenting: .slide(direction: .left))

3. implement delegate mothods

extension MyViewController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning)
        -> UIViewControllerInteractiveTransitioning? {
        return heroTransition.navigationController(navigationController, interactionControllerFor: animationController)
    }

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

All 4 comments

Sorry. This is my code

    self.navigationController?.isHeroEnabled = true
    self.navigationController?.heroNavigationAnimationType = .selectBy(presenting:.zoomOut, dismissing:.fade)

    let previewPoiViewController = PreviewPoiViewController()
    previewPoiViewController.isHeroEnabled = true
    previewPoiViewController.poi = self.pois[indexPath.row]
    self.navigationController?.pushViewController(previewPoiViewController, animated: true)

But .selectBy(presenting:.zoomOut, dismissing:.fade) not working.

Where am I wrong?

And I cannot change heroNavigationAnimationType ...
If I set it with any value, the animation doesn't change.

you should set your UINavigationControllerDelegate to something that will return a custom HeroTransition navigation delegate.

1. define your transition

fileprivate let heroTransition = HeroTransition()

2. set your navigation controller's delegate

self.navigationController?.delegate = self
self.navigationController?.heroNavigationAnimationType = .autoReverse(presenting: .slide(direction: .left))

3. implement delegate mothods

extension MyViewController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning)
        -> UIViewControllerInteractiveTransitioning? {
        return heroTransition.navigationController(navigationController, interactionControllerFor: animationController)
    }

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

They must have updated this because

navigationController.hero.navigationAnimationType = .selectBy(presenting: .zoomSlide(direction: .right), dismissing:.zoomSlide(direction: .left))

Works as expected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josmanperez picture josmanperez  路  3Comments

CalebeNP picture CalebeNP  路  5Comments

TofPlay picture TofPlay  路  4Comments

pxwinter picture pxwinter  路  3Comments

PatrykSredzinski picture PatrykSredzinski  路  3Comments