3

I have two apps, both of which force the user to use the iPhone in landscape mode, in order to have a wider screen, instead of a taller one.

One of the things I have found is that my first view will look fine, but all other views come up with their subviews (UIButtons, UIPicker, UIViews) squeezed to one side or clipped (depending on whether the elements were set to move, resize or stay in the same position as the view size changed). All my views are designed in IB in the landscape orientation. My underlying UIWindow, and everything I can think of has been laid out in landscape orientation. Even my plist file has the UIInterfaceOrientationLandscapeRight flag set.

Now, if I load all my views at the same time as my rootview controller, then I have no problems. But if I have views loaded later, they get clipped or squeezed.

The only way to get around the problem was to add the following line in my code that flips in a new view:

[coming.view setFrame:CGRectMake(0, 0, 480, 300)];

Anyone know why I need to do this? Is it just that the iPhone assumes that loaded views are 300x480 unless a transform gets applied to them?

Thanks.

ps. This is what the view looks like if I don't call setFrame, as described above:

alt text http://files.me.com/mahboud/ljhvun

All viewcontrollers that get loaded after the first one will have their screen similarly squeezed down. For some reason the first viewcontroller doesn't have this issue.

mahboudz
  • 39,196
  • 16
  • 97
  • 124
  • I can confirm this is still an issue as of iPhone OS 3.1.3. Since I have two free support incidents included in my ADC Membership, I have filed one and will let you know when I have any news. – Johannes Rudolph May 29 '10 at 14:47

4 Answers4

1

I think you want to use landscape mode in each single view in your app. And you want the nib to be landscape mode too. You can resize the view to (0,0,480,300 for statusbar, 320 for non-statusbar) in nib. And design what you want. Finally, in view controller return no for autorotate. And finally transform the view and rotate.

Mike Chen
  • 1,113
  • 8
  • 9
  • I changed all my return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); to return NO instead for all cases. The app comes up with all the views in portrait mode. – mahboudz Sep 03 '09 at 18:59
  • 2
    You should never return NO for 'shouldAutorotate'. Returning NO means that you don't want to be in any orientation, which is impossible. UIKit will log a warning in console, you should check it out. Instead, return YES for orientations you want. – Mike Chen Sep 06 '09 at 13:22
1

I had a similar problem, asked the question on SO, and then figured it out and answered it myself. You may want to check it out.

Community
  • 1
  • 1
Clay Bridges
  • 11,602
  • 10
  • 68
  • 118
0

A proper answer will depend on knowing how you are forcing landscape orientation. If you are doing this through UIViewController and company, it should be relatively simple; for other methods probably more complex.

In the simple case, you should be able to override shouldAutorotateToInterfaceOrientation: on your view controller, setup your views in Interface Builder, and set the UIInterfaceOrientation key to UIInterfaceOrientationLandscapeRight in your Info.plist and be set.

rpetrich
  • 32,196
  • 6
  • 66
  • 89
  • UIInterfaceOrientationLandscapeRight s set in the info.plist so the app is coming up in that orientation from the get go. Everything in the NIBs are setup in the same orientation. Still, the second and next views will need to have their view size set as above in order for them to display their contents properly. – mahboudz Sep 03 '09 at 18:48
0

A simple way I fixed this was to have my root view controller subclass UINavigationController, and implement shouldAutorotateToInterfaceOrientation to handle landscape view ie,

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
            (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

Every view controller that is pushed to the navigation controller seems to appear in landscape too.

zlog
  • 3,316
  • 4
  • 42
  • 82