我想在动画结束后尝试执行一个segue。这是我在viewDidAppear中的代码:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
imageViewAnimated.startAnimating()
if label.center != CGPoint(x:50, y:10) {
UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
self.label.center = self.view.center
}, completion: nil)
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
// self.label.center = CGPoint(x: 50,y:300)
self.label.alpha = 0.0
}, completion: nil)
}
if label.alpha == 0.0 {
UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
self.performSegueWithIdentifier("backSegue", sender: self)
}, completion: nil)
}
}
所以基本上我有一个向下移动并逐渐消失的标签(第一个和第二个animateWithDuration),然后我希望在标签淡出并完成另一个动画之后发生Segue。现在segue正在发生,但它立刻就会发生,并且无论我多大程度地增加延迟都不会等待。
答案 0 :(得分:2)
你在错误的地方调用segue。你想要这样的东西:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
imageViewAnimated.startAnimating()
if label.center != CGPoint(x:50, y:10) {
UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
self.label.center = self.view.center
}, completion: nil)
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
// self.label.center = CGPoint(x: 50,y:300)
self.label.alpha = 0.0
}, completion: { finished in
self.performSegueWithIdentifier("backSegue", sender: self)
})
}
}
答案 1 :(得分:0)
完成后运行您的segue代码。你必须在"完成"上编码。块。在方法完成动画后将调用完成块
UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
//if you perform segue here if will perform with animation
}, completion: { finished in
//if you perform segue it will perform after it finish animating.
self.performSegueWithIdentifier("backSegue", sender: self)
})
答案 2 :(得分:0)
您可以在动画块的完成处理程序部分编写导航代码,因为完成处理程序将在动画完成后触发。
[UIView animateWithDuration:0.25 animations:^{
//Animation changes
} completion:^(BOOL finished) {
//Navigation
}];