【问题标题】:Lock orientation regardless of rotation无论旋转如何锁定方向
【发布时间】:2012-11-05 08:56:27
【问题描述】:

我有一个 UITabBar 应用程序,其中嵌入了 UINavigation 用于某些视图。在一个特定的导航视图上,我正在显示图形/图表,最好在landscape 中显示它们,就像 iPhone 向左或向右旋转一样。该应用程序的其余部分更适合肖像。因此,无论用户如何物理旋转设备,我都想“强制”包含图形的视图以横向加载。我试过了:

#pragma mark - Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

但这似乎对视图没有任何作用。如果我在“支持的界面方向”中为我的目标选择“横向左”图标,那么它允许整个应用程序在设备旋转时重新定向。有没有办法为所有普通视图锁定我的应用纵向,为包含图表的视图锁定横向,这样应用忽略实际的设备方向?

【问题讨论】:

  • 这个方法在哪里?
  • 你使用什么版本的 iOS 和 Xcode?​​span>
  • 该方法驻留在我的 UIViewController 类中,用于我想要旋转/锁定的特定视图,我正在使用 Xcode4.5。恕我直言@stackmonster,我是根据伦敦一家顶级机构的用户体验专家的建议行事的。所以目前的问题是我不能选择,因为我不知道如何做到这一点,而不是你怀疑的相反方式。我不得不承认,使用横向显示的图表,可用性得到了显着提高。
  • @stackmonster,我想我可能误解了一些东西。我想理解你的观点,因为我是这些设备开发的新手。我不想为他们提供一些东西来单击以旋转视图。我希望视图始终以横向和仅横向加载,以便“宽”比“高”的散点图始终显示在横向中。当我被告知时,我还看到了一些高收入应用程序的示例,它们做同样的事情并设法对用户保持直观。我还没有理解你的意思吗?

标签: iphone objective-c ios orientation


【解决方案1】:

你是对的。在标签栏应用程序中,它不是被调用的单个视图控制器的 shouldAutorotateToInterfaceOrientation: 方法。仅调用选项卡栏控制器的shouldAutorotateToInterfaceOrientation 来确定视图是否以及如何定向。

但是,无论如何,各个视图控制器都应该相应地实现shouldAutorotateToInterfaceOrientation。这些方法仍然用于在推或拉视图控制器时确定动画效果的方向。

我自己从未尝试过以下操作:您可以尝试子类化标签栏控制器并根据当前向用户显示的视图相应地响应 shouldAutorotateToInterfaceOrientation但我担心 Apple 有充分的理由强迫我们为标签栏应用程序中的所有视图支持相同的方向。

【讨论】:

    【解决方案2】:

    首先我使用的是 iOS 6 SDK。

    我正在使用自定义 TabBar 控制器。 并通过以下代码集控制该 TabBar 控制器的方向

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // You do not need this method if you are not supporting earlier iOS Versions
        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    

    并且视图控制器应该包含

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
        return UIInterfaceOrientationIsLandscape(orientation);
    }
    

    这就是我所做的并且能够将视图锁定为横向或纵向(在我的情况下)。强制可能是您可以放置​​一个警报视图,说明用户将设备转为横向并向他显示图表。只是一个建议。

    【讨论】:

      【解决方案3】:

      特别是ViewController,在横屏模式下需要:

      -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      
          return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
      
      }
      

      【讨论】:

        猜你喜欢
        • 2012-11-10
        • 2013-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多