Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

statusBarFrame.height returns 1024.0 when in Landscape (iPad)

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

like image 631
Ollie Avatar asked May 16 '13 14:05

Ollie


5 Answers

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);
like image 167
cprcrack Avatar answered Nov 15 '22 20:11

cprcrack


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

like image 26
Tamara Bernad Avatar answered Nov 15 '22 21:11

Tamara Bernad


This is completely correct. The statusBarFrame is in screen coordinates. You have to use statusBarOrientation to check whether you should switch the coordinates.

like image 32
Sulthan Avatar answered Nov 15 '22 19:11

Sulthan


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.

this may help

like image 28
Cocoadelica Avatar answered Nov 15 '22 20:11

Cocoadelica


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];
like image 24
emix Avatar answered Nov 15 '22 21:11

emix