In this recipe, we will learn how to use the Core Animation framework to copy a UILabel
on the screen by animating its layer.
Create a new Single View Application in Xamarin Studio and name it LayerAnimation
. Add two labels and a button on the controller. Set the text and background color for the first label and a different background color for the second label.
Perform the following steps:
Add the
MonoTouch.CoreAnimation
namespace in theLayerAnimationViewController.cs
file as follows:using MonoTouch.CoreAnimation;
Add a field of the
CALayer
type in the class as follows:private CALayer copyLayer;
Add the following code in the
ViewDidLoad
method:this.btnCopy.TouchUpInside += (s, e) => { this.lblTarget.Text = string.Empty; this.lblTarget.BackgroundColor = UIColor.Blue; this.copyLayer = new CALayer(); this.copyLayer.Frame = this.lblSource.Frame; this.copyLayer.Contents = this.lblSource.Layer.Contents; this.View.Layer.AddSublayer(this.copyLayer...