【发布时间】:2012-04-07 06:55:00
【问题描述】:
我的应用程序主要是纵向的,但是有一个视图需要横向。
我的视图包含在 UINavigationController 中,这(显然)是导致此问题的原因。
除了一个之外的所有 UIViewControllers 都有这个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
需要 Landscape 的 UIViewController 有这个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
现在,当用户到达横向 UIViewController 时,它会以纵向显示。然后,用户可以旋转他们的手机,它会按照我的意愿横向显示(锁定为横向)。然后用户继续使用纵向 UIViewController,同样的情况发生:它从横向开始,然后他们旋转手机,它再次变成纵向(并锁定为纵向)。
UIViewController 之间似乎允许方向锁定,但是自动旋转/以编程方式更改方向被某种方式阻止了。
如何强制手机更新到正确的方向?
有一个临时解决方案:我可以检测设备的方向并显示一条消息,要求他们在不正确时旋转设备,但这不是最佳选择。
【问题讨论】:
标签: iphone objective-c ios ios5 uinavigationcontroller