IOS中整个工程是设置了支持屏幕旋转,那么如何禁止其中某个视图旋转呢?

如题,整个项目中其他视图都是可以旋转的,但是,现在希望其中一个视图只能保持纵向,不允许旋转。

用什么代码有效?

在要禁止的视图中,加入了下面的代码,无效。

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

}

  • (BOOL)shouldAutorotate

{

return NO;

}

  • (NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)

}
有哪位好心人有完整的方法,帮帮我,谢谢了

可以在delegate里面设置一个属性A。是否要横屏。
然后在(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return A;
}A
在不需要横屏的那里直接设置delegate的属性A就可以了。

  • (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(_isFull){ return UIInterfaceOrientationMaskAll; } return UIInterfaceOrientationMaskPortrait; }

说错,是在delegate里面添加这个。