【发布时间】:2011-05-05 20:25:24
【问题描述】:
我很难让我的应用正确支持所有方向。 问题在于启动。我已经完成了以下步骤:
-
添加:
<key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationPortrait</string> </array> - 确保我的所有视图控制器在 shouldAutorotateToInterfaceOrientation 中始终返回 YES
- 添加了所有默认*图像
当处于横向时 - 应用程序开始显示正确的默认图像,但实际应用程序以纵向方式启动。不会调用 willRotate... 和 shouldAutorotate.. 方法。
我什至尝试过 swizzling 方法(来自 Wordpress):
+ (void)youWillAutorotateOrYouWillDieMrBond {
NSLog(@"youWillAutorotateOrYouWillDieMrBond");
Swizzle([NSClassFromString(@"UISplitViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
Swizzle([NSClassFromString(@"UIViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
}
- (BOOL)MyShouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
NSLog(@"MyShouldAutorotateToInterfaceOrientation (%@)", self);
return(YES);
}
也没有运气。无论我做什么 - 如果设备是横向的,应用程序就会以纵向启动。
我已阅读相应的 Apple 文档 - 他们声明应用程序始终以纵向启动,但如果 VC 支持方向,则它们会自行旋转。所以看来我正在做我应该做的一切......
这里真的没有想法,如果有任何见解,将不胜感激。
【问题讨论】:
-
它应该可以工作(并且在我的项目中对我有用)。您在启动时的视图层次结构究竟是什么样的?
-
这是一个从 iPad 模板构建的标准应用程序,我有一个拆分视图控制器,所以在启动时,会显示详细 vc,并且工具栏上有一个用于打开主 vc 的按钮。
标签: ipad uiviewcontroller orientation uisplitviewcontroller landscape