【问题标题】:Xamarin iOS 10 landscapeXamarin iOS 10 横向
【发布时间】:2017-09-12 23:51:10
【问题描述】:

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

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

我已经在 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"));
    }

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

【问题讨论】:

  • 你想做什么?
  • 我想在单个视图控制器上强制横向。我更新了我的问题更准确,ty!
  • 你能看懂客观的c代码吗?
  • 不太好,但我可以试一试。尽管如此,代码必须是可翻译的并且可以在 xamarin 中运行
  • 如果有任何疑问问我试试这个:stackoverflow.com/a/24928474/3901620

标签: c# ios xamarin orientation landscape


【解决方案1】:

终于找到答案了,和iOS 10本身无关。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多