Reputation: 301
I have been using the following code to get the height of the status bar:
[UIApplication sharedApplication].statusBarFrame.size.height
This works perfectly in Portrait mode and returns the expected value (20.0), but when the application is in Landscape, I get the unexpected value of 1024.0 !!
Is anybody able to shed any light on this for me?
iOS version 6.1.3
XCode version 4.6.2
Upvotes: 8
Views: 3903
Reputation: 293
You don't need to check for the orientation, just use the UIView convenient method for converting the frame:
CGRect statusBarFrame = [self.view convertRect:[[UIApplication sharedApplication] statusBarFrame] fromView:self.view.window];
Upvotes: 1
Reputation: 19179
Use this if you want to forget about orientation or coordinates related problems:
float statusBarHeight = MIN([UIApplication sharedApplication].statusBarFrame.size.height, [UIApplication sharedApplication].statusBarFrame.size.width);
Upvotes: 13
Reputation: 1048
You might need to use the [UIApplication sharedApplication].statusBarFrame.size.width
on Landscape orientation. Same as [[UIScreen mainScreen] applicationFrame]
gives switched values on Landscape orientation
Upvotes: 10
Reputation: 3026
At what point in the app do you get this? If it's at first run, check what orientation your .xib files are in in the project. If they are in portrait then even though the app is started in landscape it hasn't had time to determine orientation and uses the dimensions of the .xib that it's creating the frontmost view controllers view from.
In iOS 6 the rotation handling and orientation detection changed significantly from iOS 5 and lower, I beleive that you can no longer rely on the orientation of the status bar for these values.
Upvotes: 1
Reputation: 130191
This is completely correct. The statusBarFrame
is in screen coordinates.
You have to use statusBarOrientation
to check whether you should switch the coordinates.
Upvotes: 4
Reputation: 5451
Clean Build your code and check whether orientationChange
methods are called.
Please specify the iOS version as well
Upvotes: -1