Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Animating views


In this recipe, we will learn how to take advantage of UIKit animations to move a UILabel on the screen.

Getting ready

Create a new Single View Application in Xamarin Studio and name it ViewAnimationApp. Add a label and button on the view of the controller.

How to do it...

Perform the following steps:

  1. Enter the following code in the ViewDidLoad method:

    this.lblOutput.BackgroundColor = UIColor.Green;
    this.btnAnimate.TouchUpInside += (sender, e) => {
      RectangleF labelFrame = this.lblOutput.Frame;
      labelFrame.Y = 380f;
      UIView.Animate(1d, 0d, UIViewAnimationOptions.CurveEaseInOut, 
        () => this.lblOutput.Frame = labelFrame, 
        () => {
          this.lblOutput.Text = "Animation ended!";
          this.lblOutput.BackgroundColor = UIColor.Red;
        });
    };
  2. Compile and run the app on the simulator. Tap on the Animate! button and watch the label transitioning to the lower part of the view.

How it works...

The UIView class contains a number of various static methods that provide animation...