Ios 限制某些视图上的自动旋转
我的应用程序包含两个表视图控制器。在第一个表中,我希望视图能够左右旋转(除了纵向模式),但是在第二个表视图控制器中(我在点击第一个表中的单元格后导航到该控制器),我希望它只能在纵向模式下查看。我试过这个代码,但没用,它一直在旋转Ios 限制某些视图上的自动旋转,ios,objective-c,view,autorotate,Ios,Objective C,View,Autorotate,我的应用程序包含两个表视图控制器。在第一个表中,我希望视图能够左右旋转(除了纵向模式),但是在第二个表视图控制器中(我在点击第一个表中的单元格后导航到该控制器),我希望它只能在纵向模式下查看。我试过这个代码,但没用,它一直在旋转 - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL) shouldAutorotate { return
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL) shouldAutorotate {
return NO;
}
注意:我确实从项目目标的摘要选项卡启用了左/右/纵向方向。任何修复?为UINavigationController创建一个类别,包括以下方法: (适用于iOS 6和iOS 5) 然后在控制器中实现这些方法 第一:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (RUNNING_IPAD) {
return UIInterfaceOrientationMaskAll;
}
else {
return UIInterfaceOrientationMaskAllButUpsideDown;
};
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (RUNNING_IPAD) {
return YES;
}
else {
return toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown;
}
}
第二:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return NO;
}
项目的旋转设置应如下所示:
事实上,我找到了解决问题的方法:
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
这将限制视图为纵向视图,即使您在项目的Traget的Summary选项卡中切换了左/右方向。选中此复选框“谢谢!我确实找到了一个更简单的答案,但我选择了这个,因为它支持ios 5和ios 6,我的只支持ios 6。
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}