Search code examples
iosios6iphone-5

Migrate issues to iphone 5 resolution


I am using XCode 4.5.1 and iOS Simulator (Retina 4 inch)

I have project that I made one yera ago. So now I want to migrate my project to new resolution.

My problem is next:

I integrate code into my project to detect which resolution I have.

CGRect screenBounds = [[UIScreen mainScreen] bounds];

But after I out value of screenBounds to NSLog I got width = 320 and height = 480, but I exprected to see 1136 × 640.

Have you got the same issues?


Solution

  • Are you sure you are using the 4inch simulator? [[UIScreen mainScreen] bounds] will return the screen bounds in points, not pixels. So in the 4inch iPhone the CGRectreturned should be 320x568.

    So if you call [[UIScreen mainScreen] bounds]:

    • <= iPhone 3GS: 320x480
    • iPhone 4 & iPhone 4S: 320x480
    • iPhone 5: 320x568

    NOTE: If you didn't add the Default-568h@2x.png file, and the app runs letterboxed the method you used will return the iPhone 4 & 4S values.

    TIP: To determine whether you are using an iPhone 5 or the rest, this code may come handy:

    #define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
    
    if( IS_IPHONE_5 )
    {
        // iPhone 5
    }
    else
    {
       // Other
    }