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?
Related to this question as it solved my problem, here two defines I use for screen width and height calculations:
If you are supporting both iOS 7 and iOS 8, this is the best solution for this problem.
Thats what I used to calculate the correct rect:
The below method can be used to find the screen bounds for a given orientation, independent of iOS version. This method will return the bounds based on the screen size of the device and will give the same CGRect value independent of iOS version.
This will give correct device in iOS7 and iOS8 both,
//You may add more devices as well(i.e.iPad).
Yes, it's now dependent on orientation.
I prefer the below method of getting the screen size in an orientation-independent way to some of the answers above, both because it's simpler and because it doesn't depend on any of the orientation code (the state of which can be dependent on the time that they are called) or on version checking. You may want the new iOS 8 behavior, but this will work if you need it to be stable on all versions of iOS.
You can use
nativeBounds
(orientation-independent)nativeBounds
Detecting the device's height:
Detecting the device's width: