0

In my main view, I add a normal UIToolbar to the bottom of the frame, in landscape it doesn't get smaller? Is this because i dont supply landscape images or am i missing something else? All of the other toolbars in the UINavigationController's all change size in landscape.

Heres how i add this one to the screen.

toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-64, SCREEN_WIDTH, 44)];
toolbar.translatesAutoresizingMaskIntoConstraints = YES;
[self.view addSubview:toolbar];
[self setupToolbarItems];

setupToolbarItems just creates some of the images for the bar buttons and sets them.

Maximilian Litteral
  • 3,059
  • 2
  • 31
  • 41

2 Answers2

6

A UIToolbar that you add yourself will not magically change height. If you want it to do so, you must change the height yourself in response to a change in app orientation.

The behavior that you have observed, where a bar changes height, is a feature of UINavigationController; it changes the height of its navigation bar and its toolbar in response to orientation change (as explained in my book: http://www.apeth.com/iOSBook/ch25.html#SBbarMetrics). But this UIToolbar does not belong to a UINavigationController so nothing happens to its height automatically. It's up to you.

matt
  • 515,959
  • 87
  • 875
  • 1,141
2

This is because you are creating the toolBar's frame but not setting it again when the view is rotated. You need to check when the screen is rotated using [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resize) name:UIDeviceOrientationDidChangeNotification object:nil];

and then in your -(void)resize; method, you need to resize the toolbar to the new window's size.

Jsdodgers
  • 5,253
  • 2
  • 20
  • 36