Detecting iPhone 6/6+ screen sizes in point values

前端 未结 16 2354
独厮守ぢ
独厮守ぢ 2020-11-29 15:44

Given the newly announced iPhone 6 screen sizes:

iPhone 6: 1334h * 750w @2x (in points: 667h * 375w)
iPhone 6+: 1920 * 1080 @3x (in points: 640h * 360w)
         


        
16条回答
  •  孤街浪徒
    2020-11-29 15:55

    this is guaranteed to compile in xcode 5 (xocde 6 at this point is still flaky, and you can't submit an ipa to itunes connect for app store approval using beta software, which xcode 6 is right now)

    the thing is xcode 5 won't recognize the nativeScale selector.. this is how you can do it in run time:

    + (BOOL)isIphone6Plus
    {
        SEL selector = NSSelectorFromString(@"nativeScale");
        if ([[UIScreen mainScreen] respondsToSelector:selector]) {
                NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
                                            [[[UIScreen mainScreen] class] instanceMethodSignatureForSelector:selector]];
                [invocation setSelector:selector];
                [invocation setTarget:[UIScreen mainScreen]];
                [invocation invoke];
                float returnValue;
                [invocation getReturnValue:&returnValue];
                NSLog(@"::: this is native scale %f", returnValue);
                return (returnValue == 3.0f);
        } else {
            // iphone 6 plus come prepackaged with iOS8.. 
            // so if the phone doesn't know what nativeScale means
            // it's not an iphone6plus phone
            return NO;
        }
    }
    

提交回复
热议问题