【发布时间】:2012-09-19 22:13:34
【问题描述】:
几分钟前我设置了 XCode 4.5 和 iOS6 模拟器。 我的应用支持 iPhone 的所有 4 方向, 纵向底部和顶部主页按钮,横向左右。
好吧,我把它放到 .plist 中,因为它是 iOS6 所要求的,而且旧的 shouldRotateTo... 方法仍然返回 YES。
但在模拟器中,应用不旋转到纵向顶部主页按钮。
为什么?这是故意的吗?它可以在设备上正常工作吗?
谢谢。
【问题讨论】:
几分钟前我设置了 XCode 4.5 和 iOS6 模拟器。 我的应用支持 iPhone 的所有 4 方向, 纵向底部和顶部主页按钮,横向左右。
好吧,我把它放到 .plist 中,因为它是 iOS6 所要求的,而且旧的 shouldRotateTo... 方法仍然返回 YES。
但在模拟器中,应用不旋转到纵向顶部主页按钮。
为什么?这是故意的吗?它可以在设备上正常工作吗?
谢谢。
【问题讨论】:
好的, 我现在自己找到了答案。
拥有是不够的
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
如果它被推入UINavigationViewController,则在您的 ViewController 中。
UINavigationViewController 也必须有这些方法。
最好通过在UINavigationViewController 上设置一个小类别来做到这一点。
这是我的UINavigationController-Rotation.h:
@interface UINavigationController (Rotation)
@end
还有我的 UINavigationController-Rotation.m:
#import "UINavigationController-Rotation.h"
@implementation UINavigationController (Rotation)
#pragma From UINavigationController
- (BOOL)shouldAutorotate {
BOOL result = self.topViewController.shouldAutorotate;
return result;
}
- (NSUInteger)supportedInterfaceOrientations {
NSUInteger result = self.topViewController.supportedInterfaceOrientations;
return result;
}
#pragma -
@end
谢谢你帮助我!
【讨论】:
iOS6 在 iPhone 上的默认行为是没有颠倒方向。
您也可以在 Safari 或地图中看到此行为。
我试图用 UIInterfaceOrientationMaskAll 覆盖它,就像 Dean 说的那样,但没有效果。 我决定不再使用颠倒模式,因为它是一种我喜欢遵循的用户界面指南,而不是混淆用户。
【讨论】:
我认为您的 viewControllers 将返回几乎颠倒的默认值。你需要实现:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
对于您想要支持所有方向的所有视图控制器。
【讨论】:
-(NSUInteger)supportedInterfaceOrientations,2) 正确的 plist 条目,3) - (BOOL)shouldAutorotate 在我的 ViewController 和最后丢失的位 4) UINavigationController 类别(看我自己的回复)。我已经有 1)-3) 并且它确实在 iPad sim 上正常工作,4) 最终让它在 iPhone 上运行。
如果其他人在遵循 Christoh 的回答后仍有问题:
我刚刚注意到项目 plist 对 iPad 和 iPhone 有单独的条目(支持的界面方向 (iPad) 和支持的界面方向 (iPhone))。
希望对您有所帮助。
【讨论】: