How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode?

后端 未结 5 1017
时光取名叫无心
时光取名叫无心 2020-11-27 16:59

How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode? Is this possible?

I\'ve tried [UIScreen mainScreen].scale and it report

5条回答
  •  粉色の甜心
    2020-11-27 17:44

    The following code may be used to get bounds, coordinateSpace, nativeScale and scale, i.e. on an iPhone 6 Plus the nativeScale is 2.608 and when the device in run in Zoomed Mode it is 2.88 (note that it is different in the simulator):

    UIScreen *mainScreen = [UIScreen mainScreen];
    NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
              NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
    

    Code for detecting iPhone 6 Plus:

    -(BOOL)iPhone6PlusDevice{
        // Scale is 3 currently only for iPhone 6 Plus
        if ([UIScreen mainScreen].scale > 2.9) return YES;
        return NO;
    }
    

    or

     -(BOOL)iPhone6PlusUnZoomed{
            if ([self iPhone6PlusDevice]){
                if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES;  // Height is 736, but 667 when zoomed.
            }
            return NO;
        }
    

    Note: If you are checking for iPhone 6 Plus, to adjust the user interface then don´t rely on .nativeScale, because the simulator and an actual device give different results.

提交回复
热议问题