Deepika
Deepika

Reputation: 3582

How to set the content size according to the size of UINavigation bar

I am resizing the navigation bar when my application switches into landscape orientation. But i am not able to set the content size of navigation bar according to its height.

Landscape image :- In this image the top left bar item and title of navigation bar are not resizing when it switches into landscape orientation....they should get re sized according to height of navigation bar.

Please suggest me any idea for it?

Thanks
Deepika

Upvotes: 2

Views: 602

Answers (3)

CedricSoubrie
CedricSoubrie

Reputation: 6697

If you have to recalculate your views, you'd better put your code into

  • - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration,
  • or -(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

shouldAutorotateToInterfaceOrientation is only supposed to respond to the question : "This view Controller should rotate or not ?".

For example :

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
     // Get the new screen width
     self.cellWidth = self.view.frame.size.width;

    // Recalculate the view
    [self rebuildTheView];
}

In most of the cases, implementing shouldAutorotate in all your ViewController is sufficient if you set the right resize settings in Interface Builder. Check that you did that before implementing didRotateFromInterfaceOrientation or willAnimateRotationToInterfaceOrientation

For example :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return [ViewToolkit orientationIsSupported:interfaceOrientation];
}

Upvotes: 0

Manjunath
Manjunath

Reputation: 4555

override the method:

- (UIView *)rotatingHeaderView
{
    return yourNavigationBar;
}

this method will get called when your device orientation takes place.

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(mainLoginView.superview == self.view || modulesView.superview == self.view)
    {
        return NO;
    }
    else
    {
        return YES;
    }
}

replace this method with your code and reply me what happens :)

Upvotes: 1

Deepika
Deepika

Reputation: 3582

I am doing in this delegate method:-

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    if(mainLoginView.superview == self.view || modulesView.superview == self.view){
        return NO;
    }else{
        [self rotateTheNavigation:contactsNavigation withOrientation:interfaceOrientation];
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}

Upvotes: 0

Related Questions