Skip to main content
 首页 » 编程设计

c#之Xamarin iOS 10 横向

2024年02月27日71wuhuacong

我的目标是在单个 View Controller 上强制横屏显示,而不是整个应用(准确地说:我想让我的相机 View Controller 只显示横屏)

我一直遇到无法使用 Xamarin.iOS 在 iOS 10 设备上强制横屏的问题。

我已经在 iOS 9 或更低版本上工作,方法是覆盖 View Controller 中的以下方法,这些方法应该仅处于横向状态。但是,这些方法似乎不会在 iOS 10 上调用。

public override bool ShouldAutorotate() 
{ 
    return true; 
} 
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() 
{ 
    return UIInterfaceOrientation.LandscapeLeft; 
} 
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() 
{ 
    return UIInterfaceOrientationMask.Landscape; 
} 

我还测试了从 ViewDidLoad 调用此方法(我不再使用此行,无法判断它是否有任何效果)

//AppDelegate 
public void ChangeOri() 
    { 
        UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation")); 
    } 

对可能的解决方法有什么建议吗?

请您参考如下方法:

我终于找到了答案,它与iOS 10本身无关。

我在 iPad 设备上遇到了问题。 iOS9 或更高版本的 iPad 获得了一项新功能:“多任务处理”。引用this线程以了解更多信息。

关键是,当您的应用设置为多任务处理时,您无法再通过代码更改方向。您必须为整个应用程序启用全屏模式才能调用我在上面的问题中发布的代码行。

在您的 plist 中设置:UIRequiresFullScreen 为 true 以执行此操作。