How to Animate a View in Your iOS App

By Jesse Feiler

Whenever you assign a new value to certain view properties (such as the frame and center properties) in your iOS app, the view is immediately redrawn and the change is immediately visible on the screen of your device.

In addition, changes to several view properties (such as those just mentioned) can be animated. This means that changing the property creates an animation that conveys the change to the user over a short period of time — and it’s all handled for you by the UIView class. What’s more, it takes only one method call to specify the animations to be performed and the options for the animation.

You can animate the following properties of the UIView class (the first three are explained previously):

  • frame: This property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system.

  • bounds: This property contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.

  • center: This property contains the known center point of the view in its superview’s coordinate system.

  • transform: Check this one out.

  • alpha: This property controls the degree of transparency. If you animate it, you can get views to fade in and fade out.

  • backgroundColor: This property allows you to transition from one color to another.