0

I'm working in iOS6, and my UIToolbar isn't getting any thinner in height when the device rotates, though it is widening to cover the increased length. Here's my code:

-(void)loadToolBar:(NSString *)t {

            //Creates a toolbar.

[bar removeFromSuperview];
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
    bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 480, 32)];
}
else bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
bar.autoresizingMask=UIViewAutoresizingFlexibleWidth;
bar.autoresizingMask=UIViewAutoresizingFlexibleHeight;
bar.autoresizingMask=UIViewAutoresizingFlexibleBottomMargin;
}

I also added this method from UIToolbar height on device rotation, but it doesn't seem to have made a difference:

- (void) layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Adjust the toolbar height depending on the screen orientation
CGSize toolbarSize = [bar sizeThatFits:self.view.bounds.size];
bar.frame = (CGRect){CGPointMake(0.f, CGRectGetHeight(self.view.bounds) - toolbarSize.height), toolbarSize};
webV.frame = (CGRect){CGPointZero, CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetMinY(bar.frame))};
}

Any thoughts about what I'm doing wrong?

Community
  • 1
  • 1
Joel Derfner
  • 2,207
  • 6
  • 33
  • 45
  • 1
    Did you call `layoutForInterfaceOrientation:` in `willAnimateRotationToInterfaceOrientation:duration` and `viewWillAppear`? – pldoverflow Jan 25 '13 at 23:33
  • This is unrelated to your issue, but it may save you some heartache: you are using UIDevice's `orientation` property and that can have some odd results, as in addition to the 4 orientations you would expect, there is also `UIDeviceOrientationFaceUp` and `UIDeviceOrientationFaceDown` I would instead use the property `interfaceOrientation` on whichever UIViewController subclass you are in, as that is of the type `UIInterfaceOrientation` which only has the 4 orientations you care about. – Simon Goldeen Jan 25 '13 at 23:57

0 Answers0