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

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?

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

Just add launch images for the iPhone and the simulator will display the proper points. Weird bug.

Related

UITabbar in Xcode 6

I have UITabbarController with 4 tabs in iPhone 4, 4s, 5, 5S it is woking fine with tabbar item image
But in iPhone 6 and iPhone 6 plus is looking wired.
Is it need to put different images for both iPhone 6 and iPhone 6 plus ?
How can I set this images.
in iphone 6
And, iPhone 6 Plus
I ran into this same issue. The problem here is not only the different resolution, but the fact that the size of the bounds is actually wider for iphone 6 and iphone 6 plus. By running the simulator on all different phone types I found the following:
Tab bar Bounds
iPhone 6 plus: 414 x 49
iPhone 6: 375 x 49
iPhone 5: 320 x 49
iPhone 4 320 x 49
This means that you must use different background images for iphone 6 and 6 plus.
I'm not sure if this is the most efficient way to do this, but it fixed it for me:
UITabBarController *tabBarController = (UITabBarController *) self.parentViewController;
UITabBar *tabBar = tabBarController.tabBar;
if ([[UIScreen mainScreen] bounds].size.height > 700) {
tabBar.selectionIndicatorImage = [UIImage imageNamed:#"tabbar-selected6Plus"];
} else if ([[UIScreen mainScreen] bounds].size.height > 600) {
tabBar.selectionIndicatorImage = [UIImage imageNamed:#"tabbar-selected6"];
} else {
tabBar.selectionIndicatorImage = [UIImage imageNamed:#"tabbar-selected"];
}
Hope that helps!
You need to make new size for iPhone 6 and iPhone 6 Plus.
Indeed they have new resolution: iPhone 6 (1334-by-750-pixel) and the iPhone 6 Plus (1920-by-1080-pixel).
Moreover if you are using auto-Layout you need to update your constraints.

Trying to detect iPhone 6 Plus in landscape orientation

I have a today widget for my app and I have been setting the layout of objects in code (Not using auto-layout) however, I need to detect when a user is using an iPhone 6 Plus. The reason for this is because in notification centre on the 6 Plus, there is a border around the edge which cuts off the labels in my widget (in landscape).
The problem is that I have been having issues trying to figure out what height value the screen is in landscape.
This is the code I have right now:
var height = UIScreen.mainScreen().bounds.size.height
if UIDevice.currentDevice().orientation.isLandscape && height == 414 {
totalBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
currentBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
budgetNameDisplay.frame.origin.x = 80
warningLabel.center = view.center
button.frame = CGRectMake(0, 0, view.bounds.width, view.bounds.height)
}
Is this the correct value for the screen height in landscape? If so, why are the labels still not moving?
Your code is good but UIDevice.currentDevice().orientation.isLandscape just does not get you correct value.
Seems like there is no bullet-proof solution to detect device orientation for Extensions.
Look at this answer for possible workaround - https://stackoverflow.com/a/26023538/2797141

Auto Layout iphone 4 - 6plus

Since apple has now introduced the iPhone 6 + 6 plus. How would I make the image for different sizes of phones? For iPhone 4 and 5/5s/5c you would do
#define IS_568_SCREEN (fabs((double) [[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSLION)
if(IS_568_SCREEN) {
//Iphone 5/5s/5c
} else {
//iphone 4s }
But how would you do it for iPhone 4s to iPhone 6 plus? Also my auto layout isn't working very well. Im trying to change the size for all my objects dependent of the phone and using auto layout to place them correctly. However its not working out, I'm doing "height", "leading space to Container Margin", "Bottom Space To Bottom layout" and "Trailing space to container". As this will be a little hard and time consuming for all the objects sizes, can I use multiple storyboards? and what I mean by that is can I have one storyboard file for iPhone 6, then one for iPhone 6 plus etc. Or if not whats the proper way of doing auto layout on the interface builder?
Here's the answer to what I was looking for, nothing complicated :)
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = screenRect.size.height;
if (screenHeight == 480) {
// do iPhone 4s stuff
} else if (screenHeight == 568) {
// do iPhone 5, 5s, 5c stuff
} else if (screenHeight == 667) {
// do iPhone 6 stuff
} else if (screenHeight == 736) {
//do iPhone 6 plus stuff
}

Retina simulator displays non-retina resolution

In XCode, I have set my IOS simulator as iPhone (Retina 3.5-inch). However in my code, when I display the screen dimensions (using Bounds CGRect), I get 320 x 480 instead of expected 640 x 960.
Any idea why ?
I am using the latest XCode and output is named iPhone 6.1 Simulator.
Thanks.
Try this:
UIScreen *mainScreen = [UIScreen mainScreen];
UIScreenMode *screenMode = [mainScreen currentMode];
CGSize realSize = [screenMode size];
Frame and bounds are measured in points not pixels. On retina devices, 4 pixels will be in 1 point while non-retina devices have 1 pixel for every point.

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?
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
}
To adapt your app to the new taller screen, the first thing you do is to change the launch image to: Default-568h#2x.png. Its size should be 1136x640 (HxW). Yep, having the default image in the new screen size is the key to let your app take the whole of new iPhone 5's screen.
Also, you'll have to take a few more steps:
Make sure, your Xibs/Views use auto-layout to resize themselves. Use springs and struts to resize views. If this is not good enough for your app, design your xib/storyboard for one specific screen size and reposition programmatically for the other.

Resources