动画完成后执行 segue
Performing a segue after animation is finished
我正在尝试在动画完成后执行转场。这是我在 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 正在发生,但它会立即执行,无论我增加多少延迟都不会等待。
运行 完成后的 segue 代码。您必须在 "Completion" 块上对其进行编码。方法完成动画后将调用完成块
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)
})
您在错误的地方调用了 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)
})
}
}
您可以在动画块的完成处理程序部分编写导航代码,因为完成处理程序将在动画完成后触发。
[UIView animateWithDuration:0.25 animations:^{
//Animation changes
} completion:^(BOOL finished) {
//Navigation
}];
我正在尝试在动画完成后执行转场。这是我在 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 正在发生,但它会立即执行,无论我增加多少延迟都不会等待。
运行 完成后的 segue 代码。您必须在 "Completion" 块上对其进行编码。方法完成动画后将调用完成块
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)
})
您在错误的地方调用了 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)
})
}
}
您可以在动画块的完成处理程序部分编写导航代码,因为完成处理程序将在动画完成后触发。
[UIView animateWithDuration:0.25 animations:^{
//Animation changes
} completion:^(BOOL finished) {
//Navigation
}];