Animation Completion

It can often be useful to know when an animation completes. For instance, you might want to chain animations together or update another object when the animation completes. To know when the animation finishes, pass a closure for the completion argument. You will use this opportunity to swap the two label references.

In ViewController.swift, update animateLabelTransitions() to use the UIView animation method that has the most parameters, including one that takes in a completion closure.

func animateLabelTransitions() {

    // Animate the alpha
    UIView.animateWithDuration(0.5, animations: {
        self.currentQuestionLabel.alpha = 0
        self.nextQuestionLabel.alpha = 1
    })
    UIView.animateWithDuration(0.5,
        delay: 0,
        options: [], ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.