Disabling segue animation

11,678

Solution 1

You can disable animations before performing the segue and after enable it again.

UIView.setAnimationsEnabled(false)
self.performSegueWithIdentifier("next", sender: nil)
UIView.setAnimationsEnabled(true)

This will perform the segue without the animation.

Solution 2

Click on segue arrow in Main.Storyboard and then:

enter image description here

Check out Animates

Solution 3

If you want to switch animate state in the code, You can duplicate your segue in the storyboard, with different identifiers, and the same origin and destination. Then make one of theme animates and the other not. Then, do performSegue with the desired identifier.

class MyNavigationController : UINavigationController {

    var firstTransitionAnimated : Bool = true // or false, based on initialization


    override func viewDidLoad() {
        super.viewDidLoad()
        var properSegue = firstTransitionAnimated ? "animated_segue" : "not_animated_segue"
        self.performSegue(withIdentifier: properSegue, sender: self)
    }
}

Solution 4

I made a custom segue, using the Swift answer in this thread:
Push segue in xcode with no animation

So:

class ShowNoAnimationSegue: UIStoryboardSegue {

    override func perform() {
        let source = sourceViewController as UIViewController
        if let navigation = source.navigationController {
            navigation.pushViewController(destinationViewController as UIViewController, animated: false)
        }
    }
}

And in Xcode, in the Attributes Inspector of the custom Segues, I have checked the 'Animates' box (YES). Now the warning is gone, so that is why I am answering my own question.

I am not really sure yet if it is a durable solution.

Share:
11,678
codeDude
Author by

codeDude

Updated on June 06, 2022

Comments

  • codeDude
    codeDude almost 2 years

    I want to Show (e.g. push) segues in my storyboard, to connect my viewcontrollers and my navigation controller. Then the navigation bars on the viewcontrollers will show correctly. For example: With show detail or present modaly, the navigation bar will disappear

    But I don't want segue animation. Xcode is giving the warning like : "Disabling segue animation is not available prior to iOS 9.0"

    And I wants deployment target of iOS 7.0 or 8.0

    How can I solve this?

    Thanks in advance.

  • codeDude
    codeDude over 8 years
    I know, but this gives the warning: "Disabling segue animation is not available prior to iOS 9.0"
  • Orkhan Alizade
    Orkhan Alizade over 8 years
    @codeDude yes, it's deprecated method. It's normal ;)
  • codeDude
    codeDude over 8 years
    Yea I will, but one question: U say 'after enable it' : Do u mean u put UIView.setAnimationsEnabled(true) direct after the performsegue in for example a IBAction?
  • Arbitur
    Arbitur over 8 years
    If you dont re-enable it no animations will work in your app.
  • codeDude
    codeDude over 8 years
    Yea I understand. But it seems so strange (for me as a relative newbie) that u perform a segue and this UIView.setAnimationsEnabled(true) will still be called after that (if u understand what I mean).
  • Arbitur
    Arbitur over 8 years
    I dont know exactly how it works in the background (Apples stuff), performSegueWithIdentifier I think will call a UIView.animateWithDuration method and if you disable animations before its called then it wont animate. Then it will go to the 3rd line where you enable animations for other animations again.
  • Tom Spee
    Tom Spee over 8 years
    This didn't work for me. I had to use only the 'false' statement and in the viewDidDisappear I had to set the animations back to 'true'.
  • Abraham Duran
    Abraham Duran about 7 years
    O.o It worked for me, and since my deployment target is iOS 9.0 there was not warning at all. But, is it deprecated? I expected a warning about it.
  • bluefox
    bluefox over 6 years
    I'm not sure why you received so many down votes, but this work for me!
  • norders
    norders almost 4 years
    This is genius.