我已经用情节提要制作了我的应用程序,并且设置了项目选项-
现在我有了一个视图控制器(TestViewController),它是故事板的一部分,我想锁定方向(只是纵向)。我已经重写了这些方法,但TestViewController会像其他方法一样旋转。ShouldAutorotate未调用,SupportedInterfaceOrientations激发,但结果与其他视图相同。
public partial class TestViewController : UIViewController {
...
public override bool ShouldAutorotate()
{
return false;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}
...
}
环境
解决方案是在AppDelegate支持的接口方向中设置如下
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations (UIApplication application, UIWindow forWindow)
{
if (forWindow != null && forWindow.RootViewController != null) {
UINavigationController nav = forWindow.RootViewController as UINavigationController;
if(nav.VisibleViewController is TestViewController){
return UIInterfaceOrientationMask.Portrait;
}
}
return UIInterfaceOrientationMask.All;
}