Animating Constraints
In this section, you are going to extend your animation to have the nextQuestionLabel property fly in from the left side of the screen and the currentQuestionLabel fly out to the right side of the screen whenever the user presses the Next Question button. In doing so, you will learn how to animate constraints.
First, you need a reference to the constraints that need to be modified. So far, all of your @IBOutlet
s have been to view objects. But outlets are not limited to views – in fact, any object in your interface file can have an outlet, including constraints.
At the top of ViewController.swift, declare two outlets for the two labels’ centering constraints.
@IBOutlet var currentQuestionLabel: UILabel!
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.