Xamarin iOS 10 横向

Xamarin iOS 10 landscape

我的目标是在单个视图控制器上强制横向方向,而不是整个应用程序(准确地说:我想让我的相机视图控制器只横向)

我已经 运行 解决了这个问题 不能 能够 在 iOS 10 台设备上强制横向显示 与 Xamarin.iOS.

我已经在 iOS 9 或更低版本 上工作了,方法是覆盖视图控制器中的以下方法,该视图控制器应该仅处于横向状态。但是,这些方法似乎没有在 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"));
    }

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

终于找到答案了,跟iOS10本身没有关系

我在 iPad 台设备上遇到了问题。具有 iOS9 或更高的 iPads 获得了新功能:"Multitasking"。请参阅 主题以了解更多信息。

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

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