我有一个应用程序,通常是一个肖像应用程序,只显示一个UIViewController的横向视图。在新的iOS 6发布之前,它可以正常工作。
我真的不明白iOS 6中的方向是如何工作的。所以我写了一个测试应用程序。这是我做的:
rootViewController中的代码:
- (NSUInteger)supportedInterfaceOrientations
{
返回UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
当我点击打开栏按钮时,我将推送另一个(SecondViewController)视图控制器,它应该处于横向模式:
- (NSUInteger)supportedInterfaceOrientations { 返回UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; }
虽然正确调用此方法,但第二个视图控制器始终处于纵向模式。
有人可以给我一些建议吗?感谢
答案 0 :(得分:1)
这是我的解决方案:
在第二个视图控制器的viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:^{
[viewController dismissViewControllerAnimated:NO completion:nil];
}];
}
这将强制第二个视图旋转到横向,这解决了我的问题。它适用于iOS 5和6。
答案 1 :(得分:1)
对于iOS-6,我已经这样做了。它运行正常
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;}
在第二个视图中
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;}
答案 2 :(得分:0)
我认为最好的解决方案是坚持官方的苹果文档。所以根据我使用以下方法,一切都在iOS 5和6上运行良好。 在所有ViewControllers中重写以下方法。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
iOS 6的方法,第一种方法返回支持的方向掩码(如其名称所示),您可以将其更改为Landscape或最适合您的套件。
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ...
}
第二个告诉你的VC哪个是VC显示时首选的界面方向。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}
这个解决方案工作顺利,我不喜欢创建宏和其他东西的想法,这就是这个简单的解决方案。 希望这有帮助...