iOS 7:如何只允许肖像方向为VC

我的所有项目都允许以横向/纵向模式查看应用程序,但是对于一个View Controller,我想禁用此function并仅以纵向显示。

我曾尝试shouldAutorotatesupportedInterfaceOrientations ,但它不工作。

如果你想要视图控制器不同的方向,在AppDelegate添加这个方法 –

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown; if(self.window.rootViewController){ UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; orientations = [presentedViewController supportedInterfaceOrientations]; } return orientations; } 

并在你的ViewController –

 -(BOOL)shouldAutorotate{ return YES; } -(NSUInteger)supportedInterfaceOrientations{ return (UIInterfaceOrientationMaskAll);//Change this according to your need } 

希望这会有所帮助。

在这里输入图像说明 转到您的项目 – >一般 – >设备方向,只select一般设置中的肖像。

你有

 UINavigationController -- UIViewController1 -- UIViewController2 

您必须inheritanceUINavigationController并实现shouldAutorotatesupportedInterfaceOrientations 。 在UIViewController1中,允许旋转任何你想要的方向。