Search code examples
iosxcode6iphone-5

xcode 6 is iphone 5 no longer 568 points in height?


So I'm trying to update my game to fit the iPhone 6 properly and i see now that when i run my game on the iPhone 5 simulator, everything is fitting as if it were an iPhone 4. I use if statements to determine the height of the device:

if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
    mylabel4.fontSize = 35;
    mylabel4.position = CGPointMake(CGRectGetMidX(self.frame) -145, CGRectGetMidY(self.frame) -130);
} else {
    mylabel4.fontSize = 35;
    mylabel4.position = CGPointMake(CGRectGetMidX(self.frame) -110, CGRectGetMidY(self.frame) - 130);
}

And like i said when i run the iPhone 5 simulator, it runs the code in the 'else' bracket. Its like the iPhone 5 is no longer 568 points in height. This was working fine until i download Xcode 6? What's going on here?


Solution

  • The UIScreen bounds behavior has changed in iOS8. Previously it would always give you width and height of the screen in portrait (so 320 x 568 on the iPhone 5), but in iOS8 it will give you width and height with respect to whatever orientation you're in, i.e. in landscape you would get 568 x 320.

    If you want to get the bounds in portrait (like before), use:

    [UIScreen mainScreen].fixedCoordinateSpace.bounds.size