Skip to content

Animations and Gestures

iOS was built from the ground up to support animations. It is absolutely required to maintain the illusion of a touch-based interface.

Simple Animation with UIKit

The UIView class provides an Animate() method to perform simple animations on views.

Move animation

Most of the time, you will perform animation by working directly with UIKit. You can animate any property of the view, e.g the following changes the position of the view change its frame:

1
2
3
4
UIView.Animate(0.5, () =>
{
    logoImageView.Frame = new CGRect(View.Center.X, View.Center.Y, logoImageView.Frame.Width, logoImageView.Frame.Height);
});

Fade in animation

To fade in, we can change the alpha of the view as follows:

1
2
3
4
5
logoImageView.Alpha = 0;
UIView.Animate(0.5, () =>
{
    logoImageView.Alpha = 1;
});

Scale animation

We can animate the Transform property of the view by scaling it up or down as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Scale by 2
var scaleTransform = CGAffineTransform.MakeScale(2, 2);
var originalTransform = CGAffineTransform.MakeScale(1, 1);

UIView.Animate(0.5, () =>
{
    logoImageView.Transform = scaleTransform;
},

    () =>
    {
        logoImageView.Transform = originalTransform;
    });

You can find more animation recipes here.

Gestures

iOS supports several gestures. You can add the gestures from the Toolbox.

Gestures