【问题标题】:Keeping my app's layouts on portrait and landscape mode in iPhone在 iPhone 中将我的应用程序的布局保持为纵向和横向模式
【发布时间】:2011-07-11 19:04:17
【问题描述】:

我的应用中有一个视图,其中包含三个分段按钮控制器,并且我将其设计为纵向模式。当我旋转屏幕时,整个用户界面......就是不对。

我的问题是,我应该分别为纵向和横向模式设计吗?如果是这样,我该怎么做?

ps。实际上,我不需要 iPhone 应用的旋转支持,但我计划为 iPad 制作相同的应用,其中每个视图都必须是可旋转的。谢谢。


编辑: 刚刚找到了很好的例子 Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?

【问题讨论】:

    标签: iphone user-interface layout rotation landscape


    【解决方案1】:

    我会说这取决于内容。有时在 Interface Builder 的 Inspector 中正确设置 UI 元素的自动调整大小就足够了,并且您会获得令人满意的效果,但是在某些情况下,仅调整视图大小并不能充分利用屏幕空间。例如,在您的情况下,仅将分段控件扩展到全宽可能不如将它们彼此相邻排列以在底部放置文本那样好。

    如果您要分别为这两种模式进行设计,您可以将它们作为不同的视图并在它们之间进行相应的切换。很好的例子可以在iPhone Cookbook的第4章找到。作者所做的就是在方向改变时切换视图如下:

    - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
     { 
         if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
            || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
           self.view = landscapeView;
        else if ((interfaceOrientation == UIInterfaceOrientationPortrait)
            || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
           self.view = portraitView;
        return YES;
     }
    

    【讨论】:

    • 将这段代码放在 willRotateToInterfaceOrientation 中不是更好吗?
    【解决方案2】:

    我强烈建议您在文档中查找 UIViewController 类并阅读所有内容(假设您尚未阅读)。您需要的关键方法包括willRotateToInterfaceOrientation:duration:,描述如下:

    willRotateToInterfaceOrientation:duration: 在用户界面开始旋转之前发送到视图控制器。

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

    参数toInterfaceOrientation 用户的新方向 界面。可能的值为 在 UIInterfaceOrientation 中描述。 duration待处理的持续时间 旋转,以秒为单位。 讨论子类可能会覆盖 这种方法来执行额外的 紧接前的行动 回转。例如,您可以使用 此方法禁用视图 交互,停止媒体播放,或 暂时关闭昂贵的绘图 或实时更新。你也可以使用它 将当前视图换成一个 反映了新的界面 方向。当这个方法是 调用,interfaceOrientation 属性仍然包含视图的 原始方向。

    这个方法被调用,不管 您的代码是执行一步还是 两步旋转。

    可用性 适用于 iOS 2.0 和 稍后。

    听起来您还应该包括:

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

    【讨论】:

      【解决方案3】:

      只需将控件的autoresizingMask 属性设置为

      UIViewAutoresizingFlexibleWidth
      

      【讨论】:

        【解决方案4】:

        我一直在寻找解决方案,最终选择以编程方式设置布局元素,如this 文章中所述。

        【讨论】:

          猜你喜欢
          • 2014-03-12
          • 2015-06-14
          • 1970-01-01
          • 1970-01-01
          • 2013-10-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多