Question

I've got a custom UIToolBar which doesn't adjust it's height to match the navigationbar on the top of the screen when I rotate to landscape mode. The height stays the same which makes it look a bit weird. The default toolbar from the UINavigationController actually reduces in size when rotated to landscape (unfortunately I can't use it because of push/pop transition issues). The current resizing mask is :

[ customToolbar setAutoresizingMask: ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin ) ];

If I add "UIViewAutoresizingFlexibleHeight" strange things happen...so I'm not quite sure if I should use this.

Please let me know if anyone knows the correct way to auto resize/rotate the UIToolBar to match the navigationbar height.

Was it helpful?

Solution

If you need to resize your custom toolbar with the same aspect ratio as standard navigation bar you should implement willAnimateRotationToInterfaceOrientation controller method like this:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    CGRect navigationToolbarFrame = self.navigationController.navigationBar.frame;
    CGRect customToolbarFrame = CGRectOffset(navigationToolbarFrame, 0.0, navigationToolbarFrame.size.height);
    [UIView animateWithDuration:duration animations:^{
        self.customToolbar.frame = customToolbarFrame;     
    }];
}

OTHER TIPS

The easiest way to achieve that is to create a UINavigationcontroller and present it as a modal view, I use something like this:

NewViewController *f = [[NewViewController alloc]initWithNibName:@"NewView"
                                            bundle:[NSBundle mainBundle]];
self.newViewController = f;

[f release];

UINavigationController *navigationController = [[UINavigationController alloc]
                           initWithRootViewController:self.newViewController];

 [self presentModalViewController:navigationController animated:YES];

Since you're presenting the view as a navigatiocontroller you can use the toolbar property.

Not sure about masks, but you can resize the view in -willRotateToInterfaceOrientation:duration:. Simply change the frame there to suit your needs. You can also do it in -willAnimateRotationToInterfaceOrientation:duration:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top