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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.