【问题标题】:Differentiate in terms of User Interface between iPhone 4 , iPhone 5 and iPad [duplicate]iPhone 4、iPhone 5 和 iPad 在用户界面方面的区别 [重复]
【发布时间】:2012-10-05 02:51:29
【问题描述】:

可能重复:
How to detect iPhone 5 (widescreen devices)?

我们可以用

来区分 iPad 和 iPhone
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone/UIUserInterfaceIdiomPad

但是如何根据用户来区分 iPhone 4 和 iPhone 5

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:

    引用this post:

    #define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
    

    然后只需检查:

    if( IS_IPHONE_5 )
    {}
    else
    {}
    

    请注意,如果您不想,则不必将其定义为宏。简化版:

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
        if ([[UIScreen mainScreen] bounds].size.height == 568) {
            //5
        }else{
            //not 5
        }
    }else{
        //iPad
    }
    

    是的,这适用于横向。即使设备的方向发生了变化,设备的高度也保持不变。获取 UIScreen 的高度与获取视图的高度不同。

    【讨论】:

    • 横向模式可以用吗?
    猜你喜欢
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多