I need to detect when the user rotate the device to Landscape orientation. I can detect when the orientation changed with the code below:
UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
this.orientationObserver = UIDevice.Notifications.ObserveOrientationDidChange(MyRotationCallback);
private void MyRotationCallback(object sender, NSNotificationEventArgs e)
{
// Landscape or Portrait ?
}
It works, but I can't tell if it was changed to landscape or portrait. How I can I detect this?
UIDevice.CurrentDevice.Orientation
LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait
In your ViewDidLoad
(or similar):
Foundation.NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), DeviceRotated);
void DeviceRotated(NSNotification notification)
{
System.Diagnostics.Debug.WriteLine(UIDevice.CurrentDevice.Orientation);
}
LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With