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

Transforming views


In this recipe, we will rotate a UILabel by applying a transformation. Furthermore, the rotation will be animated.

Getting ready

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

How to do it...

Perform the following steps:

  1. Add the MonoTouch.CoreGraphics namespace in the TransformViewAppViewController.cs file as follows:

    using MonoTouch.CoreGraphics;
  2. Enter the following ViewDidLoad method in the TransformViewAppViewController class:

    private double rotationAngle;
    public override void ViewDidLoad ()
    {
      base.ViewDidLoad ();
      this.btnRotate.TouchUpInside += async (sender, e) => {
        this.rotationAngle += 90;
        CGAffineTransform rotation = 
        CGAffineTransform.MakeRotation((float)this.DegreesToRadians(this.rotationAngle));
        await UIView.AnimateAsync(0.5d, () => this.lblOutput.Transform = rotation);
        this.lblOutput.Text = string.Format("Rotated to {0} degrees.", this.rotationAngle);
      ...