This post is for LearnSwiftLA members as a reference to my talk. Slides can be found here.
iOS Animation Basics
Birth of a UIViewController
We’ll start off with something simple, animating a UILabel. We’ll place it in the middle of our View Controller, and in code after we set the
IBOutlet we’ll set up
viewWillAppear so our UILabel is off screen while the view is appearing.
center is the center point of the frame and
x is the x-coordinate. So when we subtract
view.bounds.width we’re basically telling our UILabel to move completely off screen.
If we run our app now, we’ll see our UILabel is nowhere to be seen.
Now we’ll set up our first animation! We need our UILabel to show up where we set it up in our storyboard. To do this we’ll use
We’re undoing the changes in
viewWillAppear but we’re animating the change inside
If we added another label below and wanted to animate it, we could also give it a delay