In this chapter, we will learn how to rotate the user interface according to the screen orientation.
Perform the following steps:
Add a label to the view the controller.
Override the
ShouldAutoRotate
method:public override bool ShouldAutorotate () { return true; }
Override the
GetSupportedInterfaceOrientations
method:public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations () { return UIInterfaceOrientationMask.All; }
Override the
DidRotate
method:public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation) { base.DidRotate (fromInterfaceOrientation); this.lblOrientation.Text = this.InterfaceOrientation.ToString(); }
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...