2014年10月24日 星期五

[iOS] How to detect iPhone 6 Plus screen size

簡單列出一下 iPhone 6 & iPhone 6 Plus 解析度:
        iPhone 6(4.7"):   750w x 1334h @2x (in points: 375w x 667h)
iPhone 6 Plus(5.5"): 1242w x 2208h @3x (in points: 414w x 736h)

本來天真的以為要判斷是否為 iPhone 6 Plus 只要查看 w or h 即可,但發現用模擬器執行 NSLog 印出 [UIScreen mainScreen].bounds 發現竟然跟 iPhone 5(4") 的解析度相同為 640w x 1136h,代誌不是憨人所想的那樣,查了一下發現可以用 nativeScale 來判斷,程式碼如下所示:

- (BOOL)IsiPhone6Plus
{
    if([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)])
    {
        // Nativescale is always 3 for iPhone 6 Plus
        if([UIScreen mainScreen].nativeScale > 2.1)
            return YES;
    }

    return NO;
}

Reference: http://stackoverflow.com/questions/25756087/detecting-iphone-6-6-screen-sizes-in-point-values

沒有留言:

張貼留言