Sefran2 Sefran2 - 6 months ago 44
iOS Question

landscape mode problem with a navigation bar

I have a ViewController that manages a view in which I have a Table View, an ImageView and a Navigation Bar.
When I put it in the landscape mode the Navigation Bar doesn't resize to 32, it still remains to 44
I tried first to use the autosizing in IB without success, then I tried to put this code in the ViewController

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
//[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
CGRect frame = self.navigationController.navigationBar.frame;
if (UIInterfaceOrientationIsPortrait(orientation)) {
frame.size.height = 44;
} else {
frame.size.height = 32;
}
self.navigationController.navigationBar.frame = frame;
}


but nothing.
How can I solve this issue?

Answer

I made a mistake, there isn't a navigationController, so I linked the navigation bar in IB with the outlet navBar in the code and I've used

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation  duration:(NSTimeInterval)duration {
//[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
CGRect frame = self.navBar.frame;
if (UIInterfaceOrientationIsPortrait(orientation)) {
    frame.size.height = 44;
} else {
    frame.size.height = 32;
}
self.navBar.frame = frame;  
}

It works now, I've only a problem with the image view