Maximilian Litteral
Maximilian Litteral

Reputation: 3089

UIToolbar doesn't get smaller in landscape

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.

Upvotes: 0

Views: 772

Answers (2)

Jsdodgers
Jsdodgers

Reputation: 5312

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.

Upvotes: 2

matt
matt

Reputation: 535306

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.

Upvotes: 6

Related Questions