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 layers


In this recipe, we will learn how to use the Core Animation framework to copy a UILabel on the screen by animating its layer.

Getting ready

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.

How to do it...

Perform the following steps:

  1. Add the MonoTouch.CoreAnimation namespace in the LayerAnimationViewController.cs file as follows:

    using MonoTouch.CoreAnimation;
  2. Add a field of the CALayer type in the class as follows:

    private CALayer copyLayer;
  3. 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...