等到动画完成后再继续 Swift

Wait until animation finishes before moving on Swift

在下面的代码中,如何等到动画完成后再继续?我希望代码脉冲 "Sending" 两次和 "Sent" 一次,但据我所知它直接进入 "Sent""

UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 0.0
            }, completion: nil)
        countdownLabel.text = "Sending"
        UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 1.0
            }, completion: nil)
        UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 0.0
            }, completion: nil)
        countdownLabel.text = "Sending"
        UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 1.0
            }, completion: nil)
        UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 0.0
            }, completion: nil)
        countdownLabel.text = "Sent"
        cancelButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
        UIView.animateWithDuration(1.0, delay: 0.25, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.countdownLabel.alpha = 1.0
            }, completion: nil)

我如何才能等到动画的一个部分结束后再继续下一部分?谢谢!

这就是完成处理程序的用途。将下一个动画放在上一个动画的完成中。

把这个丢在操场上。如果将其拆分为函数,则可以保持其可读性。不过这个下周三就破了

var view = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
view.backgroundColor = UIColor.blackColor()


func animationOne() {
    UIView.animateWithDuration(1.0,
        delay: 0.0,
        options: nil,
        animations: {view.alpha = 1},
        completion: {finished in animationTwo()})
}

func animationTwo() {
    UIView.animateWithDuration(1.0,
        delay: 0.0,
        options: nil,
        animations: {view.alpha = 0},
        completion: {finished in animationThree()})
}

func animationThree() {
    UIView.animateWithDuration(1.0,
        delay: 0.0,
        options: nil,
        animations: {view.alpha = 1},
        completion: {finished in print("done")})

}

animationOne()

It appears swift2 doesn't like it when the options are nil:

选项现在是数组形式的选项集。零变成了 []

UIView.animateWithDuration(2.0, delay: 0.0, options: [], animations: { () -> Void in

    self.view.alpha = 1.0

    }, completion: { (finished: Bool) -> Void in
     // next animation
})