【问题标题】:Forcing a viewcontroller to be portrait monotouch iphone强制视图控制器为纵向单点触控 iphone
【发布时间】:2013-04-14 17:16:51
【问题描述】:

我的应用中有一个视图控制器,它希望始终以打印模式显示。此屏幕的对象是在运行时添加的,并且基于 protaint 模式。这是我的第一个视图控制器。

我尝试了一些代码,例如:

first

second

Third

但他们都无法帮助我。可以知道这个状态的任何其他解决方案吗?

我在那里发现了一些东西:

Monotouch - View created in landscape orientation is displayed in portrait orientation

但我不知道如何使用它。任何身体都可以帮忙吗?

我用这个代码

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            // Return true for supported orientations
            if (UserInterfaceIdiomIsPhone) {
                return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown  );
            } else {
                return true;
            }

        }


        public override bool ShouldAutorotate ()
        {
            return true  ;
        }
        public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation ()
        {
            return UIInterfaceOrientation.Portrait ;
        }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
        {
            return UIInterfaceOrientationMask.Portrait  ;
        }

但它们都不起作用。

autoroatate 函数从不调用 :(

【问题讨论】:

  • 所以你在不同的视图中有多个方向?在您的“支持的界面方向”中,您是否勾选了所有四个?并且只有在运行时启动的版本中,您才希望始终保持纵向,这是一个正确的假设吗?
  • 是的,视图控制器是我的应用程序中的第一个视图控制器,我希望它是纵向的,并且在支持的界面方向中我有 3 个四边形

标签: ios iphone uiviewcontroller xamarin.ios rotation


【解决方案1】:

也许您正在应用完成午餐模式中使用导航控制器。如果正确,您应该覆盖 UINavigation 控制器并将您自己的旋转机制添加到此。请看这段代码:

public class RltNavigationController : UINavigationController
{
    public RltNavigationController () : base ()
    {
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
    {
        if(this.TopViewController is HomeScreen )
            return UIInterfaceOrientationMask.Portrait ;
        else 
            return UIInterfaceOrientationMask.AllButUpsideDown  ;

    }

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
    {
        // Return true for supported orientations
        if(this.TopViewController is HomeScreen )
            return (toInterfaceOrientation == UIInterfaceOrientation.Portrait );
        else 
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown) ;

    }
}

【讨论】:

  • ShouldAutotrotateToInterfaceOrientation 自 iOS6 起已弃用
  • ShouldAutorotateToInterfaceOrientation 适用于 ios 5 设备,GetSupportedInterfaceOrientations 适用于 ios 6 及更高版本。两种方法都被覆盖了
猜你喜欢
  • 2013-05-18
  • 2013-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-25
  • 2012-12-21
  • 1970-01-01
  • 2014-10-13
相关资源
最近更新 更多