wcoder / Xamarin.Plugin.DeviceOrientation

Cross-platform plugin to work with screen orientation of mobile device.
MIT License
61 stars 19 forks source link

ios: after unlock, orientation doesn't restore normal value. #24

Open fatfatson opened 4 years ago

fatfatson commented 4 years ago

lock for landscape first, then unlock, the screen remains landscape,even if the device is potrait.

breyed commented 3 years ago

To repro on iOS, add the following to a Xamarin.Forms page:

protected override void OnAppearing() {
    base.OnAppearing();
    CrossDeviceOrientation.Current.LockOrientation(DeviceOrientations.Landscape);
}

protected override void OnDisappearing() {
    base.OnDisappearing();
    CrossDeviceOrientation.Current.UnlockOrientation();
}

In AppDelegate.cs add:

[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow) =>
    Plugin.DeviceOrientation.DeviceOrientationImplementation.SupportedInterfaceOrientations;

Wrap the page in a NavigationPage. Set the navigation page style like this:

Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetModalPresentationStyle(navigationPage.On<Xamarin.Forms.PlatformConfiguration.iOS>();

Push the navigation page with PushModalAsync.

At runtime, start in portrait. Cause the page to be pushed. The app orientation will change to landscape; however, keep the phone physically portrait. Cause the navigation page to pop. The orientation doesn't return to portrait.