mr-sk
mr-sk

Reputation:

Why is my toolbar not visible when in landscape mode?

My aim was to get the application functioning in both landscape and portrait mode, and all I could figure out to do it was this code below. The app was working fine in portrait, but when switched to landscape, the text wouldn't expand (to the right) to fill up the additional space. I made sure my springs/struts where set, and that the parents had "allowResizing" selected in IB.

Here's what I've done instead:

- (void) willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration: 
(NSTimeInterval)duration {
  UIInterfaceOrientation toInterfaceOrientation = self.interfaceOrientation;

  if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    self.myView.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
  }
  else {
    self.myView.frame = CGRectMake(0.0, 0.0, 480.0, 256.0);
  }
}

Note that it looks just fine in portrait mode (toolbar appears):

Portrait http://mr-sk.com/img/land.png

But the toolbar is gone in landscape mode:

Landscape http://mr-sk.com/img/por.png

Any ideas?

Upvotes: 0

Views: 1297

Answers (2)

TimM
TimM

Reputation: 293

If you use Interface Builder - you get this same result if you don't specify constraints in the object inspector to pin the toolbar to both edges and the bottom (click on the little red lines to specify constraints).

You can also do the same in code - you need to lookup how to do this (but its easier in IB)

Upvotes: 3

Matt Gallagher
Matt Gallagher

Reputation: 14968

There are a few reasons why it could be messing up... maybe your UIToolbar has the wrong parent. Maybe a layoutSubviews is being run and moving it somewhere strange. Or something else.

I recommend you implement a didRotateFromInterfaceOrientation: on your view controller and read the frame of the UIToolbar after the rotation to see where it has gone. This will be the best way to discover the exact problem.

Upvotes: 0

Related Questions