In this recipe, we will learn how to take advantage of UIKit animations to move a UILabel
on the screen.
Create a new Single View Application in Xamarin Studio and name it ViewAnimationApp
. Add a label and button on the view of the controller.
Perform the following steps:
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; }); };
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.