如题,整个项目中其他视图都是可以旋转的,但是,现在希望其中一个视图只能保持纵向,不允许旋转。
用什么代码有效?
在要禁止的视图中,加入了下面的代码,无效。
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
{
return NO;
}
{
return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)
}
有哪位好心人有完整的方法,帮帮我,谢谢了
UINavigationController添加一个分类,然后重新构造函数
#import "UINavigationController+Category.h"
@implementation UINavigationController (Category)
(BOOL)shouldAutorotate {
return [self.viewControllers.lastObject shouldAutorotate];
}
(NSUInteger)supportedInterfaceOrientations {
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
@end
在需要不旋转的界面中加上,你上述的代码
supportedInterfaceOrientations只调用一次,你应该还有底层控制器吧,navigation之类的,具体可以参考一下这篇文章,解决的就是你的这个问题,http://blog.163.com/soyo_gogogo/blog/static/17141407720148303253630/
单单写viewController不够的