How to get UINavigationController and rotation to play nicely?

Discussion in 'iOS Programming' started by fenrus110, Oct 17, 2008.

  1. fenrus110 macrumors regular

    Mar 24, 2008
    Setting shouldAutorotateToInterfaceOrientation to YES is easy enough and works fine for plain views.

    But if I'm pushing UIViewControllers into a UINavigationController and try to rotate, it doesn't seem to quite go in the right spot and leaves a bunch of nasty black space.

    It gets even more tricky when you try to set the navigation bar to hidden, it seems to do crazy things.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Usually NavBars rotate just fine. When you see some black space around your views it means that you haven't set up the autoresizing mask correctly.

    Regarding hidden navbars and rotation I haven't played with this so I don't know what the story is. Possibly the navbar isn't being resized when it's hidden and it gets confused if it's hidden, rotated, and then unhidden. Maybe you can force it to resize even though it's hidden. This may be an apple bug.

    The navbar is a different height in landscape vs portrait.
  3. Niiro13 macrumors 68000

    Feb 12, 2008
    – willRotateToInterfaceOrientation:duration:  
    – didRotateFromInterfaceOrientation:
    What works for me is to hide the navigation bar in the first method.

    Then unhide it in the second method.

    What I also do is make sure I set the frame sizes in the second method.
  4. fenrus110 thread starter macrumors regular

    Mar 24, 2008
    there is something totally bugged out about this. I'm in a screen with a UITableView in landscape mode. I touch a row to push the next screen in, which is also in landscape mode.

    In my viewWillAppear, I setNavigationBarHidden:YES

    In my viewDidLoad I put in:
    self.view.frame = CGRectMake(0, 0, 480, 320);

    I've tried varying combinations, but the result is always the same, I get a 32 pixel high black space at the bottom. (which is the height of a landscape navigation bar)

    I tried adding a toolbar to the bottom, and I could not interact with the buttons because they were in this hidden 32 pixel high space.
    toolbar.frame = CGRectMake(0, 288, 480, 44);

    Now, if I setNavigationBarHidden:YES, in my didSelectRowAtIndexPath, the 32 pixel appears at the top. So if I want to put stuff to have the appearance of having something there, I put in a negative Y value. But if I need to interact with that area, I'm out of luck.

Share This Page