landscape mode problem with a navigation bar

Sefran2 picture Sefran2 · Nov 18, 2010 · Viewed 12k times · Source

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

Sefran2 picture Sefran2 · Nov 19, 2010

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