强制景观iOS 6

我期待在我的应用程序中有一个视图有横向方向。 当手动旋转时,我已经设法使视图保持在横向,但是如果设备已经是纵向的,它将保持纵向,而不pipe它支持的方向(使用supportedInterfaceOrientations方法设置)。 有没有办法让视图自动旋转? 我努力了:

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 

但是这不起作用。

任何build议将不胜感激!

一种方法是通过重写preferredInterfaceOrientationForPresentation但是为了调用viewController,必须呈现 (如模态中所示),而不是像这里提到的那样推送:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { NSLog(@" preferred called"); return UIInterfaceOrientationPortrait; } 

为了在UINavigationController中显示你的viewController,使用:

 UINavigationController *presentedNavController = [[UINavigationController alloc] initWithRootViewController:protraitViewController]; [self presentViewController:presentedNavController animated:YES completion:nil]; 

要使UINavigationController尊重你当前的viewController的方向首选项,使用这个简单的类别,而不是子分类。

此外,这部分苹果的文档是一个很好的阅读,以更好地理解iOS的方向处理。

在UIViewController中定义以下仅用于横向视图的以下内容:

 - (UIInterfaceOrientation) supportedInterfaceOrientations { return UIInterfaceOrientationLandscapeLeft; } // or right or both 

这应该防止您的视图出现在肖像中。 从iOS文档:

声明首选的演示文稿方向当视图控制器全屏显示其内容时,有时内容在以特定方向进行查看时显示效果最佳。 如果内容只能以该方向显示,那么只需从supportedInterfaceOrientations方法返回该内容即可。