【问题标题】:How do I have only one view in landscape and the rest is portrait? [duplicate]我如何只有一个横向视图,其余是纵向? [复制]
【发布时间】:2014-08-26 20:24:13
【问题描述】:

我有一个用户在纵向模式下使用的应用。

我有一个画廊功能,我只想在横向模式下工作。

但是我的问题是我的方向设置为这样,所以我的所有视图都是纵向的。

如何强制横向加载一个视图?

我将如何在我的故事板上以横向模式显示该视图?

【问题讨论】:

  • 您可以同时允许“纵向”和“倒置”设备方向,然后以编程方式强制方向。但我不确定在User eXperience 方面这是一个好习惯:你不应该强迫你的用户旋转它的设备,特别是如果你不允许他在你的应用程序的其余部分这样做。跨度>
  • 我如何以编程方式强制它?
  • 首先通过搜索 SO ;) stackoverflow.com/questions/9826920/…
  • 不起作用,已弃用的方法! :(

标签: ios iphone xcode screen-orientation


【解决方案1】:

在我的例子中,我覆盖了 NavigationController 并覆盖了以下方法:

public myNavController : NavigationController
{
    public override bool ShouldAutorotate ()
    {
        return ShouldAllowLandscape(); // implemet this method to return true only when u want it to
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
    {
        var shouldAllowOtherOrientation = ShouldAllowLandscape (); // same here
        if (shouldAllowOtherOrientation) 
        {
            return UIInterfaceOrientationMask.AllButUpsideDown;
        } 

        return UIInterfaceOrientationMask.Portrait;
    }

    bool ShouldAllowLandscape ()
    {
        return TopViewController is xController; // implement this to return true when u want it
    }
}

请记住,此代码在 Xamarin.iOS 中,但您可以在 Obj-C 中执行完全相同的操作 然后你可以覆盖你的UIViewControllers 中的各个方法,以根据需要返回 true 或 false

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多