18

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.

Birju
  • 1,132
  • 11
  • 32
codeDude
  • 499
  • 1
  • 5
  • 18

4 Answers4

28

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.

Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • 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? – codeDude Oct 15 '15 at 12:11
  • 1
    If you dont re-enable it no animations will work in your app. – Arbitur Oct 15 '15 at 12:12
  • 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). – codeDude Oct 15 '15 at 12:14
  • 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. – Arbitur Oct 15 '15 at 12:16
  • 13
    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'. – Tom Spee Oct 22 '15 at 14:40
12

Click on segue arrow in Main.Storyboard and then:

enter image description here

Check out Animates

Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79
6

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)
    }
}
Abbas Sabeti
  • 141
  • 2
  • 9
3

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
codeDude
  • 499
  • 1
  • 5
  • 18