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

Adjusting the UI orientation


In this chapter, we will learn how to rotate the user interface according to the screen orientation.

Getting ready

Create a new Single View Application in Xamarin Studio and name it UIOrientationApp.

How to do it...

Perform the following steps:

  1. Add a label to the view the controller.

  2. Override the ShouldAutoRotate method:

    public override bool ShouldAutorotate ()
    {
      return true;
    }
  3. Override the GetSupportedInterfaceOrientations method:

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
    {
      return UIInterfaceOrientationMask.All;
    }
  4. Override the DidRotate method:

    public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
    {
      base.DidRotate (fromInterfaceOrientation);
      this.lblOrientation.Text = this.InterfaceOrientation.ToString();
    }
  5. Compile and run the app on the simulator. Rotate the simulator by pressing the Command key and either the left or right arrow keys. The current user interface orientation will be shown on the simulator...