views:

845

answers:

2

I have a subclass of UIViewController which handles a UIView. The viewcontroller is presented modally (it slides up from the bottom of the screen). At the top of the view, i have added a navigation bar. Note that this bar is not handled by a navigation controller.

I want to get the navbar to shrink in height when the view rotates to landscape (similar to how it behaves when it is handled by a UINavigationController). However, I can't set its autoresizing mask to flexible height in IB, and doing so in code causes the navbar to disappear completely.

Is there a way to do this? How is it done by the UINavigationController?

P.S. I would prefer not having to resort to a scaling transform, since this would mess up the text in the title.

EDIT: I solved it with a little help, read the answer posted below.

+1  A: 

Rather than set it's autoresizing mask, why don't you just check the current orientation in viewWillAppear, as well as in didRotateFromInterfaceOrientation, and set the appropriate frame?

- (void) updateNavBar {
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if ((UIInterfaceOrientationLandscapeLeft == orientation) ||
        (UIInterfaceOrientationLandscapeRight == orientation)) {
        myNavBar.frame = CGRectMake(0, 0, 480, 34);
    } else {
        myNavBar.frame = CGRectMake(0, 0, 320, 44);
    }
}
- (void) viewWillAppear {
    [self updateNavBar];
    // ... SNIP ...
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [self updateNavBar];
    // ... SNIP ...
}
Douglas Mayle
I gave it a try, but it didn't behave the way I wanted it to. more specifically, the bar button items and the title didn't scale, so the top went off screen. Also, the nav bar itself didn't actually scale, so the gradient was off. I'll try to do some manual resizing of the subview, and see if it works...
MW
I tried using transforms of different kinds ob the subview, but I couldn't get it to look nice.
MW
A: 

I found the solution, and in hindsight i feel rather stupid. I just had to include flexible bottom margin in the navbar's autoresize mask. Credit is due to user RayNewbie in this thread, which pointed me to the solution:

http://discussions.apple.com/thread.jspa?messageID=8295525

MW