【发布时间】:2012-09-28 13:22:00
【问题描述】:
我给了一个带有 10 个视图控制器的应用程序。我使用导航控制器来加载/卸载它们。
除了一个以外,其他所有人都处于纵向模式。假设第 7 个 VC 在横向。我需要它在加载时以横向呈现。
请建议一种在 IOS 6 中强制将方向从纵向变为横向的方法(在 IOS 5 中也可以使用)。
这是我在 在 IOS 6 之前的做法:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIViewController *c = [[[UIViewController alloc]init] autorelease];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
呈现和关闭模态 VC 会强制应用检查其方向,因此会调用 shouldAutorotateToInterfaceOrientation。
我在 IOS 6 中的尝试:
- (BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
加载时,控制器保持纵向。旋转设备后,方向改变就好了。但我需要让控制器在加载时自动旋转为横向,因此用户必须旋转设备才能正确查看数据。
另一个问题:将设备旋转回纵向后,方向变为纵向,尽管我在supportedInterfaceOrientations 中仅指定了UIInterfaceOrientationMaskLandscape。为什么会这样?
此外,上述 3 个方法中的 NONE 被调用。
一些(有用的)数据:
- 在我的 plist 文件中,我指定了 3 个方向 - 几乎都是颠倒的。
- 该项目是在 Xcode 4.3 IOS 5 中启动的。包括 xibs 在内的所有类都是在 Xcode 4.5 IOS 6 之前创建的,现在我使用最后一个版本。
- 在 plist 文件中,状态栏设置为可见。
- 在 xib 文件(我想在横向)中,状态栏为“无”,方向设置为横向。
感谢任何帮助。谢谢。
【问题讨论】:
-
我有同样的问题,你解决了吗?
-
我讨厌新的 ios 6。我必须更改所有应用程序才能使方向正常工作。
-
yop, @bagusflyer, das ist da life of da 程序员)))
-
这个问题就像我的问题,我解决了。解决方案:stackoverflow.com/questions/14658268/…
-
您的问题对我来说是一个解决方案。我也想要同样的,我刚刚写了你的 ios6 代码,它对我有用。它会自动为我加载横向视图。
标签: iphone objective-c orientation ios6