if (UIDevice.CurrentDevice.CheckSystemVersion(16, 0))
{
var windowScene = (UIApplication.SharedApplication.ConnectedScenes.ToArray()[0] as UIWindowScene);
if (windowScene != null)
{
var nav = UIApplication.SharedApplication.KeyWindow?.RootViewController;
if (nav != null)
{
// Tell the os that we changed orientations so it knows to call GetSupportedInterfaceOrientations again
nav.SetNeedsUpdateOfSupportedInterfaceOrientations();
windowScene.RequestGeometryUpdate(
new UIWindowSceneGeometryPreferencesIOS(UIInterfaceOrientationMask.Portrait),
error => { }
);
}
}
}
else
{
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
}
1条答案
按热度按时间xbp102n01#
这对我在所有版本的iOS上都有效:
您还需要在AppDelegate中管理
GetSupportedInterfaceOrientations
,以便它返回正确的方向。