Search code examples
swiftuiviewcontrolleruinavigationcontrolleruikituistoryboardsegue

Removing Animation From UINavigationController Pushed Unwind?


I have a simple push segue from one view controller to another. I want both segues (original and unwind to be unanimated).

In the attached playground, specifying false for the segue does, indeed remove the PUSH animation, but not the UNWIND animation.

Is there a way to remove the implicit animation in the UNWIND segue?

import UIKit
import PlaygroundSupport

class SourceViewController : UIViewController {
    @objc func goDestination(_: Any) {
        navigationController?.pushViewController(DestinationViewController(), animated: false)
    }
    
    override func loadView() {
        view = UIView()
        navigationItem.title = "SOURCE"
        navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(goDestination(_:)))
    }
}

class DestinationViewController : UIViewController {
    override func loadView() {
        view = UIView()
        view.backgroundColor = .yellow
        navigationItem.title = "DESTINATION"
    }
}

PlaygroundPage.current.liveView = UINavigationController(rootViewController: SourceViewController())

Solution

  • Those animations are fully customizable from the UINavigationControllerDelegate, check out the first "Supporting Custom Transition Animations" method

    https://developer.apple.com/documentation/uikit/uinavigationcontrollerdelegate

    Some details here https://www.youtube.com/watch?v=jWckfDNUJVY at 23 minutes.