1

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

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

第一的

第二

第三

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

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

Monotouch - 以横向创建的视图以纵向显示

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

我用这个代码

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

4

1 回答 1

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) ;

    }
}
于 2013-04-15T11:26:13.707 回答