Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UINavigationBar landscape height while device is in portrait

I have a simple question: I want to find out the height of a UINavigationBar in landscape while my device is in portrait. Is this possible and if so, how?

Some background:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectZero];
[navBar sizeToFit];

NSLog(@"navBar: %@", NSStringFromCGRect(navBar.frame));

This returns the correct height for the current device orientation, for example 44. That means that UINavigationBar's sizeToFit method must somehow look at the current device orientation. Is there any way to get find out what the height would be in landscape without going to landscape?

like image 322
Johannes Fahrenkrug Avatar asked Nov 01 '22 17:11

Johannes Fahrenkrug


1 Answers

Why not grab and set that information in willAnimateRotationToInterfaceOrientation. By overriding this method you should be able to get the info you desire prior to the view being shown.

In other words, don't worry about it until you are actually in the process of changing your orientation.

willAnimateRotationToInterfaceOrientation

like image 148
Wizkid Avatar answered Nov 15 '22 07:11

Wizkid