Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3212936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:53:23+00:00 2026-05-17T14:53:23+00:00

So I have this iPhone app with a nested setup like this: [RootViewController]->[UITabBarController]->[UINavigationController]->[subViewControllers]. Everything

  • 0

So I have this iPhone app with a nested setup like this:
[RootViewController]->[UITabBarController]->[UINavigationController]->[subViewControllers]. Everything is built programmatically, not in Interface Builder.

I’m simply trying to support all device orientations. All of my AutoResizing masks are set up and everything rotates and expands/contracts as necessary. Everything except for the NavigationController’s navBar and Toolbar. (Normally, these views auto-resize automatically depending on the orientation. i.e. In landscape, the navbar and toolbar should automatically resize to about 32px, and 44px in Portrai mode.) What’s peculiar is that the subView of the navigation controller is resizing, but the actual navBar and toolbar are not. In other words, the content stretches/shrinks about 12 px or so in whichever direction as though the navbar and toolbar resized. This appears to be the autoresizing masks doing their job.

So in order to attempt to solve this situation, I created a category for UINavigationController that responds to ‘willRotateToInterfaceOrientation:duration:’ in order to trigger the ‘sizeToFit’ selector. (This technique came from another post on Stack Overflow, with a similar issue.) I discovered, in my research, that only the outermost view controller receives this message, however, so I have my root view controller call this on tab controller, which in turn calls it on the nav controller, etc. This took care of that problem, and now my nested view controllers are being notified when the outer view is rotated. Using the sizeToFit technique, both the nav bar and toolbar are resizing on their own. However, that still leaves the issue of repositioning the toolbar, in order to make up for the offset from the size change. (Since our view coordinates in iPhone start at top left.)

What makes this tricky to do within the willRotate method, is that we have no way of knowing what the new bounding view dimensions will be, nor do we know what our current orientation is. (Unless you have deviceOrientationNotifications turned on, which I don’t.) All we have to work with is what the new orientation will be, and what our toolbar’s current frame values are. I could hard-code this and calculate frame adjustments the old-fashioned way using a piece of scratch paper, but I really want to retain the dynamic view sizing features without making any assumptions about the device’s screen dimensions.

Therefore, using the following code, I managed to remedy this by simply ‘bumping’ the toolbar by 12px relative to the size it just became. In order to prevent it from over-bumping when the user flips the device, I use the current toolbar’s frame height to derive the current orientation. (This means I still am making an assumption regarding the toolbar’s before and after sizes, but I feel better about that since I can influence that to a degree as opposed to trying to programmatically resize the device’s physical screen.)

@implementation UINavigationController (BLUINavigationControllerAutoRotate)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return TRUE;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

    // Resize the navBar
    [[self navigationBar] performSelector:@selector(sizeToFit)
                               withObject:nil
                               afterDelay:(0.5f * duration)];

    // Read our current frame size
    CGRect toolbarFrame = self.toolbar.frame;

    // Prevent over adjusting when flipping the device
    if ((toolbarFrame.size.height < 38
         && (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
             || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
        || (toolbarFrame.size.height > 38
            && (toInterfaceOrientation == UIInterfaceOrientationPortrait
                || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)))
    {
        // We are already resized and repositioned.
        return;
    }

    // Calculate and apply the toolbar offset
    const NSInteger delta = 12;     // the difference in size between 44 and 32 px.
    toolbarFrame.origin.y += ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
                              || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) ? (delta) : (-delta);
    self.toolbar.frame = toolbarFrame;

    // Resize the toolbar
    [[self toolbar] performSelector:@selector(sizeToFit)
                         withObject:nil
                         afterDelay:(0.5f * duration)];

}

@end

So, now I have properly behaved NavigationBar and Toolbar. The end-user will never know that I had to implement all of this extra work-around in order to re-enable what seems like is supposed to be a standard behavior. So my question is, why do I have to do all of this? Is there a better approach I should know about, or something that I simply am not doing elsewhere? (i.e. [navigationController setAutomaticallyResizesToolbarOnRotate:TRUE]; or something like that?) Like I said, this seems like it’s supposed to be pre-wired, so for me to have to finagle with forwarding messages and forced triggers feels like an over-engineered hack rather than the proper solution.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:53:24+00:00Added an answer on May 17, 2026 at 2:53 pm

    You’re passing on the willRotateToInterfaceOrientation message to the tab view controller from your root view controller – why not pass on all the other rotation messages and see if that helps? i.e.

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
        [tabBarController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
        [tabBarController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation  {
        [super didRotateFromInterfaceOrientation:toInterfaceOrientation];
        [tabBarController didRotateFromInterfaceOrientation:toInterfaceOrientation];
    }
    
    - (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
        [tabBarController willAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
    
    - (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        [super didAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation];
        [tabBarController didAnimateFirstHalfOfRotationToInterfaceOrientation:toInterfaceOrientation];
    }
    
    - (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willAnimateSecondHalfOfRotationFromInterfaceOrientation:toInterfaceOrientation duration:duration];
        [tabBarController willAnimateSecondHalfOfRotationFromInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
    

    I’d be interested to see what happens if you pass all these to your tab bar controller – your problem seems like something that should happen automatically, instead of being all the extra work you’ve done!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set my compression like this for my NSMutableUrlRequest on my iphone app
I have plist in my iphone app and I want to read and write
So my girlfriend and her sisters were playing around with this iPhone app where
I'm building an iphone app, and i have my first view call a second
I am trying to make a button in my IPhone app which changes an
HIi friends, i working on a IPhone Web App as its kinda new to
Question 1 I want to make IPhone application that uses OpenID for authentication. I
What is the stuff between the [] in the log message below? I get
I was given some high-res images, which were originally made for a printed magazine,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.