我想在我的故事板中显示(例如推送)segue,以连接我的viewcontrollers和我的导航控制器。然后,viewcontrollers上的导航栏将正确显示。 例如:使用show detail或present modaly,导航栏将消失
但我不想要segue动画。 Xcode发出如下警告:"在iOS 9.0和#34之前,禁用segue动画不可用;
我想要iOS 7.0或8.0的部署目标
我该如何解决这个问题?
提前致谢。
答案 0 :(得分:22)
您可以在执行segue之前以及再次启用之后禁用动画。
UIView.setAnimationsEnabled(false)
self.performSegueWithIdentifier("next", sender: nil)
UIView.setAnimationsEnabled(true)
这将在没有动画的情况下执行segue。
答案 1 :(得分:3)
我使用此主题中的Swift答案制作了自定义segue:
Push segue in xcode with no animation
所以:
class ShowNoAnimationSegue: UIStoryboardSegue {
override func perform() {
let source = sourceViewController as UIViewController
if let navigation = source.navigationController {
navigation.pushViewController(destinationViewController as UIViewController, animated: false)
}
}
}
在Xcode中,在自定义Segues的Attributes Inspector中,我检查了'Animates'框(YES)。现在警告消失了,这就是我回答自己问题的原因。
我不确定它是不是一个持久的解决方案。
答案 2 :(得分:3)
答案 3 :(得分:0)
如果要在代码中切换动画状态,则可以在情节提要中复制您的segue,使用不同的标识符以及相同的起点和终点。然后使一个主题动画,而另一个不动画。然后,使用所需的标识符执行performSegue。
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)
}
}