强制viewcontroller是纵向单触摸iphone

时间:2013-04-14 17:16:52

标签: ios iphone uiviewcontroller xamarin.ios rotation

我的应用中有一个想要始终以prtaint模式显示的视图控制器。此屏幕的对象在运行时添加并基于protaint模式。这是我的第一个viewcontroller。

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

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函数从不调用:(

1 个答案:

答案 0 :(得分: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) ;

    }
}