如何在iOS 7和iOS 8中locking设备方向

我的应用程序有问题。 我无法locking我的应用程序的方向。 我只需要将一个视图控制器locking到横向模式,其余的都是纵向模式。

这是我的应用程序的层次结构。

*Navigation Controller *TabBarController *ViewControllers 

您只需从shouldAutorotate NO返回NO ,并将横向方向从supportedInterfaceOrientation返回到您想要的横向中。

另一方面,请从shouldAutorotate方法返回NO ,并从supportedInterfaceOrientation屏蔽肖像方向掩码。

在所有的viewControllers中:

  -(BOOL)shouldAutorotate { return NO; } 

在你想要的景观中:

 - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; } 

在你想要的肖像控制器中:

  - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } 

使用下面2这种方法locking设备方向到风景。

 - (NSUInteger)supportedInterfaceOrientations{ [super supportedInterfaceOrientations]; return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight); } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) { return YES; } // Return YES for supported orientations return NO; } 

使用NavigationController

 -(BOOL)shouldAutorotate -(NSUInteger)supportedInterfaceOrientations -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 

如果您使用“show segue(push)”,这些方法从不会被调用。

改变赛格'showDetail'而不是'显示'