【问题标题】:iPad app force rotationiPad 应用强制旋转
【发布时间】:2012-12-25 22:20:14
【问题描述】:

我有一个简单的导航应用程序,其中 95% 的视图以横向模式显示。通过仅在纵向模式下显示有意义的一个视图,我在其中插入了以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

问题在于,当应用导航到视图(从横向视图)时,它不会将方向切换为纵向,只有当设备旋转时,它才会对齐到纵向并保持纵向。是否可以在加载视图时强制它以纵向模式加载?

提前感谢

【问题讨论】:

  • 你能显示视图控制器层次结构吗?上面的旋转代码仅适用于您的顶部视图控制器,而不是您推入导航控制器的视图控制器。
  • 在这种情况下,最重要的项目是导航控制器,它支持我认为的所有方向。我通过以下方式将新的肖像控制器推入导航控制器:[self.navigationController pushViewController:portraitDetailsViewContoller animated:YES];
  • 视图控制器调用 [self.navigationController pushViewController:portraitDetailsViewContoller animated:YES];代码行是横向的。
  • 这不是苹果的一大禁忌吗?我的意思是您试图在设备本身处于横向模式时强制以纵向模式查看?苹果门卫有一个非常触发快乐拒绝手指。只是说。

标签: iphone ios xcode ipad uiinterfaceorientation


【解决方案1】:

我认为你应该通过:UIViewController 类的shouldAutoRotateToInterfaceOrientation 方法。

如果您的 UIView 支持方向,则此函数返回 YES。如果你return YES 只对portrait orientation,那么 iPhone 会自动被放在那个方向。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

【讨论】:

    猜你喜欢
    • 2011-01-08
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多