I ran the following code in both iOS 7 and iOS 8:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f",
(landscape ? @"Yes" : @"No"),
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height);
The following is the result from iOS 8:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
Comparing to the result in iOS 7:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
Is there any documentation specifying this change? Or is it a temporary bug in iOS 8 APIs?
It is not a bug in iOS 8 SDK. They made bounds interface orientation depended. According to your question about some reference or documentation to that fact I will highly recommend you to watch
View Controller Advancements in iOS 8
it is 214 session from WWDC 2014. The most interesting part (according to your doubts) isScreen Coordinates
which starts at 50:45.I needed a quick helper function that kept the same behavior as iOS7 under iOS8 - this allowed me to swap out my
[[UIScreen mainScreen] bounds]
calls and not touch other code...Yes, indeed, screen size is now orientation dependent in iOS 8. Sometimes, however, it's desired to get a size fixed to portrait orientation. Here is how I do it.
Yes, it's orientation-dependent in iOS8.
I wrote a Util method to resolve this issue for apps that need to support older versions of the OS.
My issue was related to UIWindows frame which was going in minus. So made the code as below in MyViewController -(NSUInteger)supportedInterfaceOrientations Method
And its work for me try it.
Used slightly modified mnemia's solution, that one without iOS version check, using min/max on mainscreen bounds.
I needed a
CGRect
so gotCGRect
from mainscreen bounds and changedsize.width=min(w,h)
,size.height=max(w,h)
. Then I called that OS-independent getCGRect
function in two places in my code, where I getting screen size forOpenGL
, touches etc. Before fix I had 2 problems - on IOS 8.x in landscape mode display position ofOpenGL
view was incorrect: 1/4 of full screen in left bottom part. And second touches returned invalid values. Both problems were fixed as explained. Thanks!