I have an iOS Cocos2D app designed to run in landscape mode. When simulating the app on an iPhone 5 device, I use the following code to get the screen dimensions:
CGSize screenSizeInPixels = [CCDirector sharedDirector].winSizeInPixels;
Execution of this code yields a screenSizeInPixels.width = 1136.0f and a screenSizeInPixels.height = 640.0f. But when I simulate/execute the same code in Xcode 6, I get just the opposite: a screenSizeInPixels.width = 640.0f and a screenSizeInPixels.height = 1136.0f.
Why are the pixel dimensions reversed?
This is a Bug in iOS SDK:
https://github.com/cocos2d/cocos2d-swift/issues/973
One Solution in that manually set the desired orientation in the info.plist, then everything seems to work ok. It works for me.
Related
I've just restarted work on a project I last worked on 4 years ago. Back then, I was using Xcode 3.2 and an iPad 2. Now I am on Xcode 8.1 and an iPad Air 2.
I can build and run the project just fine with Xcode 8.1 but there is something strange going on when getting the screen size using
CGRect rect = [[UIScreen mainScreen] bounds];
It returns 768x1024 pixels on my iPad Air 2 which can't be true because the iPad Air 2's native resolution is 1536x2048. 768x1024 is the resolution of the iPad 2, my old device.
Furthermore, not only does bounds return the wrong dimensions, I can also clearly see that the graphics I draw to my view have been upscaled.
So my assumption is that my project is running in some sort of legacy/compatibility mode that tries to make the app believe it is still running on an iPad 2 in a resolution of 768x1024 instead of a resolution twice as big. Could that be the case or what is the explanation for this phenomenon?
So how can I get this to work correctly? i.e. how can I get bounds to return 1536x2048 and stop automatic upscaling? I have already looked through the various options in Xcode but I don't see anything that could explain the behaviour I'm seeing here. My deployment target is set to iOS 10.1 so I don't really see why my app is put in this strange legacy mode or whatever it is...
You are confused here you are getting correct bounds from here
CGRect rect = [[UIScreen mainScreen] bounds];
1536x2048 is the resolution of iPad Air 2 not its screen size i.e. iPad Air 2 is supporting #2x resolution.
If you will check bounds of iPad Air 2 then you will get 768x1024
I've recently updated Xcode to 7 so I could start developing against iOS 9. Upon first launching my application, I noticed that the screen size/scale is off compared to how it looks on iOS 8, both on the iPhone 6 device.
Here is how it looks correct on iOS 8:
Here is how it looks incorrect on iOS 9:
If you also notice, both of those images are the same exact size.
Note how the AdMob banner has white space on the left/right, I'm assuming AdMob just knows to center it. Also the big white space to the right of the table view and the button down on the bottom.
Also, when in iOS 8, and putting a break point in the main delegate method, the main window has a frame of (0 0; 320 568). The layer on the window is also the same.
On the flip side, when in iOS 9, and putting a break point in the main delegate method, the main window has a frame of (0 0; 375 667). The layer on the window is also the same.
That explains why the difference in the look of the app in iOS 8 vs. iOS 9, but I do not know why iOS 8 looks the way I want it to and iOS 9 doesn't. Is there some setting that I'm missing?
EDIT:
I've also since figured out that the bounds of the mainScreen is different between when this runs in iOS 8 vs. iOS 9. The screenBounds of the mainScreen is set to the same frame as up above, and I have no clue why it is different between the two iOS versions.
EDIT 2:
So I just created a brand new project and tested this out. I do not get the same behavior as explained up above in my first edit. When I view the mainScreen bounds, in both iOS 8 and iOS 9, it is (0,0;375,667);
I just cannot figure out what is causing this to happen so I can fix it.
EDIT 3:
After toying around quite a bit last night, it turns out that the launch images are causing this to happen. If I remove the launch images of Default-568#2x.png from the list, then it displays properly. Very odd that something like this can effect the scale. I still didn't figure out how to solve this yet though because you have to have launch images or apple will reject the app, so I'm keeping this open until I have more time tonight to toy around with it.
Are you testing on devices or simulators? If on device, your iOS 8 device might have Display Zoom enabled: Settings → Display & Brightness → Display Zoom. This would make an iPhone 6 (375 ✕ 667) think it’s an iPhone 5 (320 ✕ 568).
Apple has always looked at features of your application to decide what screen sizes your app can handle, and simulated a screen size that it is sure your app can cope with.
For example, you have probably added a launchscreen image in 320 x 568 pixels. That tells iOS that you know about 4" devices; without that your app would run in a 320 x 480 screen. To support an iPhone 6, you would have had to add a 375 x 667 launch screen; without it iOS reports that you have only an iPhone 5 sized screen.
Now you are using the iOS 9 SDK. When you use that SDK Apple expects you to handle any screen size, so suddenly it reports the true screen size of 375 x 667 (414 x 736 on a 6+). You can't use hardcoded sizes anymore; you have to adapt your app to the screen bounds.
I didn't find any solution for my problem anywhere in Stack Overflow or other sites. So here is the problem:
I am developing an iOS Universal app, portrait orientation only. When I run it on iOS 8.3 simulator window and all other views layout seems to be normal.
But when I run the same app on iOS 7.1 simulator, which I downloaded from developer's site for Xcode 6, the window height seems to be approximately 100 px smaller.
I checked the couple of view frames for both simulators.
7.1 simulator was returning width = 320, height = 480
8.3 simulator returned width = 320, height = 568
I am using storyboard and constraints.
I am pretty sure that a lot of people had this problem, so I am hoping to hear some useful advices from you.
Check out the screenshots below:
Added Answer as per Brian Tompsett - 汤莱恩's Suggestion.
Solution is already done on comments.
iOS 7.x does not support LaunchScreen.xib
So, Manually add the LaunchScreens in the assets folder and you will get desired output.
Go to Project settings --> Target --> App Icons and Launch Images
Launch Image Source was empty so, open it and chose to Migrate from Images.
So now window height is back to 568 on iOS 7.1 simulator
I found the issue while trying to update our project to adapt the change in iOS8 and iPhone6. After a series of testing and debugging, I do not know the reason that causes this issue. Only clue I found is that when creating UIWindow object in iPhone6, landscape, the UIWindow object has different angle (orientation) than the main screen (status bar angle). And after trying to transform the UIWindow object, it actually goes to a weird size. I do not know why and how this is happening. Your help is highly appreciated!!
[Environment]
Xcode 6.0.1
build 6A317
simulator: iPhone 6, iPhone 6+
[Issue]
There’s weird behavior occurred when trying to resize the UIWindow object to full screen (frame = [UIScreen mainScreen].bounds )
[Normal Behavior] (OK)
1. Create UIWindow object in portrait orientation
2. Turn the device to landscape
3. UIWindow object will be resized to full screen
4. Resize OK
[Abnormal behavior] (FAIL)
1. Create UIWindow object in landscape orientation
2. UIWindow object size correct, but orientation is wrong
3. After trying to transform to correct angle(orientation), the frame origin/size is messed up
[Test Result]
Testing simulator: iPhone 4s, iPhone 5, iPhone 5s, iPhone 6, iPhone 6+
Environment: Xcode 6.0.1, build 6A317, iOS8 simulator
Screenshots link
I have exactly the same issue after I upgrade my project to the new SDK and new device.
Just by adding an empty storyborad as launch screen in the project setting fixed this issue for me:
Had the same problem. Turns out I was calling initWithFrame on UIWindow with CGRect in pixels instead of points.
I have a couple applications built pre-auto-layout (but w/ Springs and Struts to support iPhone 5+) that I'm trying out in the iPhone 6 and 6 Plus simulator and they actually look quite good. However, I can't tell if the Springs and Struts are actually doing their job so-to-speak or if they're just being scaled. There must be some obvious thing I'm missing where it says which? Also, do auto-layout apps just automatically convert when recompiled with the latest SDK for iPhone 6 so they're not just scaling as long as 3X artwork is provided (in the case of 6 Plus)?
You can easily see, if your app runs in scaled mode by outputting the bounds and the native bounds screen of the main screen:
println("bounds = \(UIScreen.mainScreen().bounds)")
println("nativeBounds = \(UIScreen.mainScreen().nativeBounds)")
Without a designated launch images the output of the iPhone 6 Plus Simulator is:
bounds = (0.0,0.0,320.0,480.0)
nativeBounds = (0.0,0.0,960.0,1440.0)
The native bounds are 3 times the scaled bounds. This is the reason behind the #3x display.scale.
In case of the iPhone 6 Plus nativeScale also helps:
println("main screen native scale = \(UIScreen.mainScreen().nativeScale)")
println("main screen scale = \(UIScreen.mainScreen().scale)")
nativeScale will always be 3.0. scale will be 2.0 if the simulator does scaling.
To get a comprehensive understanding of the new resolutions see this great blog entry: http://www.paintcodeapp.com/news/iphone-6-screens-demystified
Use a different launch image for iPhone 6, iPhone 6 Plus and all the rest.
If you see a specific lunch image you know your app is not scaled and that it is running in the device's native resolution.
The only way I was able to tell was to go home and see if the status bar text was smaller than it was in my app. A smaller home screen status bar implies it is being scaled. If the status bar text is the same size within your app in the iPhone 6 sim as it is on the home screen of the simulator, then it is using your springs/struts or autolayout instead of scaling