Disabling segue animation

余生颓废 提交于 2020-01-01 04:17:16

问题


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.


回答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.




回答2:


Click on segue arrow in Main.Storyboard and then:

Check out Animates




回答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.




回答4:


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


来源:https://stackoverflow.com/questions/33147271/disabling-segue-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!