codeDude
codeDude

Reputation: 519

Disabling segue animation

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.

Upvotes: 18

Views: 12404

Answers (4)

Abbas Sabeti
Abbas Sabeti

Reputation: 151

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)
    }
}

Upvotes: 6

codeDude
codeDude

Reputation: 519

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.

Upvotes: 3

Orkhan Alizade
Orkhan Alizade

Reputation: 7569

Click on segue arrow in Main.Storyboard and then:

enter image description here

Check out Animates

Upvotes: 12

Arbitur
Arbitur

Reputation: 39091

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.

Upvotes: 29

Related Questions