【问题标题】:Best way to manage screen height differences on iPhone 5 and others在 iPhone 5 和其他设备上管理屏幕高度差异的最佳方法
【发布时间】:2012-12-03 19:02:19
【问题描述】:

管理 iPhone 5 和其他版本之间屏幕高度差异的最佳方法是什么?

如果我们使用故事板或 xib,它会相应地调整它的大小。但是如果整个视图都是以编程方式构建的,我们如何处理这个问题。

目前我所做的是获取整个屏幕高度并根据此高度设置其余 UI 元素,例如 height * .7 或 height *.5 ..

但它仍然没有给我最好的体验。

谢谢,

【问题讨论】:

    标签: iphone ios uiview storyboard iphone-5


    【解决方案1】:

    您可以检查[UIScreen mainScreen].bounds.size.height(可能是,将其用作静态方法或做一个#define)并根据屏幕高度进行屏幕设计。另一种方法是使用view.autoresizingMask 属性来调整视图。

    例如:-

    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    

    如果您正在为 iOS 6 构建,您可以使用Auto layout 功能。

    【讨论】:

      【解决方案2】:

      在您的 viewDidLoad 中,只需检查屏幕大小就像这样...

      - (void)viewDidLoad
      {
         [super viewDidLoad];
          CGRect screenBounds = [[UIScreen mainScreen] bounds];
         if (screenBounds.size.height == 568)
         {
             //iPhone 5
         }
         else
         {
             // iPhone 4
         }
      
      }
      

      【讨论】:

        猜你喜欢
        • 2020-02-12
        • 1970-01-01
        • 1970-01-01
        • 2012-09-06
        • 1970-01-01
        • 2012-09-29
        • 2012-10-23
        • 2013-10-12
        • 1970-01-01
        相关资源
        最近更新 更多