landscape mode problem with a navigation bar

Discussion in 'iOS Programming' started by franium, Nov 18, 2010.

  1. franium macrumors member

    Joined:
    Nov 18, 2010
    #1
    Hi, 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
    Code:
    - (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?
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    What is [self navigationController] pointing to? If your custom view controller is inside a UINavigationController, that should just shrink the navigation bar down for you in landscape for free. It's not working?
     
  3. franium, Nov 19, 2010
    Last edited: Nov 19, 2010

    franium thread starter macrumors member

    Joined:
    Nov 18, 2010
    #3
    You are right, I made a mistake... my view isn't in a nav controller... so I link the navbar in the code with an IBOutlet and I've used
    Code:
    - (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;
    	
    }
    Now, it works, but the image under the navbar remains still there, so there is a space between the two. The autosizing masks seem not work.
    How can I fill that space with the image from the code repositioning the image?
     

Share This Page