How to detect iPhone 5 (widescreen devices)?

前端 未结 24 1788
我寻月下人不归
我寻月下人不归 2020-11-22 00:50

I\'ve just upgraded to XCode 4.5 GM and found out that you can now apply the \'4\" Retina\' size to your view controller in the storyboard.

Now if I want to create a

24条回答
  •  故里飘歌
    2020-11-22 01:19

    Borrowing from Samrat Mazumdar's answer, here's a short method that estimates the device screen size. It works with the latest devices, but may fail on future ones (as all methods of guessing might). It will also get confused if the device is being mirrored (returns the device's screen size, not the mirrored screen size)

    #define SCREEN_SIZE_IPHONE_CLASSIC 3.5
    #define SCREEN_SIZE_IPHONE_TALL 4.0
    #define SCREEN_SIZE_IPAD_CLASSIC 9.7
    
    + (CGFloat)screenPhysicalSize
    {
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            if (result.height < 500)
                return SCREEN_SIZE_IPHONE_CLASSIC;  // iPhone 4S / 4th Gen iPod Touch or earlier
            else
                return SCREEN_SIZE_IPHONE_TALL;  // iPhone 5
        }
        else
        {
            return SCREEN_SIZE_IPAD_CLASSIC; // iPad
        }
    } 
    

提交回复
热议问题