限制某些视图的自动旋转

我的应用包含两个表格视图控制器。 在第一个我希望能够左右旋转视图(除了肖像模式),但是在第二个表视图控制器(我从第一个表中点击单元格后导航)我想要它只能在肖像模式下查看。 我试过这个代码,但它没有工作,它一直在旋转。

- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL) shouldAutorotate { return NO; } 

注意:我确实从项目目标的摘要选项卡启用了左/右/纵向方向。 任何修复?

为UINavigationController创build一个包含以下方法的类别:

(适用于iOS 6和iOS 5)

 - (BOOL)shouldAutorotate { return self.topViewController.shouldAutorotate; } - (NSUInteger)supportedInterfaceOrientations { return self.topViewController.supportedInterfaceOrientations; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } 

然后在你的控制器中实现这些方法

第一:

 - (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; } 

项目的旋转设置应该如下所示:

设置

其实我find了我的问题的解决scheme:

 -(BOOL)shouldAutorotate{ return YES; } -(NSInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } 

即使您在项目的“Traget”的“摘要”选项卡中切换了左/右方向,也会将视图限制为纵向。