【问题标题】:How to write my custom code for desiging any layout which automatically fixces the layout for iPhone 4 and iPhone 5如何编写我的自定义代码来设计任何自动修复 iPhone 4 和 iPhone 5 布局的布局
【发布时间】:2012-12-03 08:47:11
【问题描述】:

我没有在我的项目中使用任何 XIB。我正在通过自定义代码设计我的视图或任何东西。直到 iPhone 4 都很好。但是对于 iPhone 5,当我想让应用程序与 iPhone 5 兼容时,我遇到了一个问题。它的屏幕高度比以前的 iPhone 大。我想让它自动兼容。

【问题讨论】:

    标签: iphone xcode ios5 ios6


    【解决方案1】:

    将以下行添加到您的 .m/.h 文件中

    #define IS_IPHONE_5 ( [ [ UIScreen mainScreen ] bounds ].size.height == 568 )
    

    如果设备是 iPhone5 即 4 英寸屏幕,这将返回 YES。像这样使用它:

    if(IS_IPHONE_5) {
         //set frame of objects for 4 inch screen - iPhone 5 or new iPod Touch
    }else {
         //set frame of objects for 3.5 inch screen - IPhone 4S or earlier devices
    }
    

    我在我的许多应用中都使用了相同的解决方案。希望这可以帮助。 :)

    【讨论】:

    • 它有帮助,但如果我们想框住视图中的'
    • 如果你想框住视图(我认为你需要子视图),你可以使用视图的自动调整大小属性。假设您有一个视图“a”,其中包含一个 imageView “b”。如果您希望“b”的大小根据“a”更改,请使用类似:- b.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
    • 还有其他属性也可以相对控制框架的“原点”属性。用它们做实验会让你有更多的理解。自从 4 英寸 iPhone 到来之后,这个属性就变得非常重要了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    相关资源
    最近更新 更多