In this recipe, we will learn how to make an app that is aware of changes in the device orientation.
Perform the following steps:
Add a label to the controller.
In the
DeviceOrientationAppViewController
class, override theViewWillAppear
method and implement it with the following code:private NSObject orientationObserver; public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); this.orientationObserver = UIDevice.Notifications.ObserveOrientationDidChange((s, e) => { this.lblOrientation.Text = UIDevice.CurrentDevice.Orientation.ToString(); }); }
Override the
ViewWillDisappear
method by using the following code:public override void ViewWillDisappear (bool animated) { base.ViewWillDisappear (animated); NSNotificationCenter.DefaultCenter...