0

So I have an app with a view controller which changes view when rotated to landscape. In this view, the user can tap large images in a UIScrollView which will push a new view controller. However, the view controller which is pushed does NOT support landscape orientation.

This is a problem as when the user taps on the image in the first controller, the second one loads and automatically rotates the portrait-only view into landscape mode which looks ugly.

So the question is; how can I (probably in viewWillAppear) force the orientation to change to portrait even though the user is holding the device in a landscape position? I've tried [[UIApplication sharedApplication] setStatusBarOrientation:] as mentioned elsewhere but with no joy.

NonatomicRetain
  • 301
  • 4
  • 14
  • Ah, after much googling, the following is just what I needed: http://stackoverflow.com/questions/1682639/any-way-to-silence-the-uidevice-setorientation-warning – NonatomicRetain Aug 21 '11 at 11:34

1 Answers1

1

The pushed navigation controller which is to support portrait-only orientation should have this method implemented:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

Set it to return the supported orientation/s, so in this case it'd be:

return (interfaceOrientation == UIInterfaceOrientationPortrait); // and probably portrait upside-down, if it's on the iPad
Luke
  • 11,426
  • 43
  • 60
  • 69
  • No this doesn't work. This only works on subsequent device rotations. The problem is the phone is already in landscape so the new view gets pushed in landscape. Your answer makes perfect sense though; I don't know why it doesn't work... – NonatomicRetain Aug 21 '11 at 10:23
  • Is it possible to change the pushed navigation controller to a view controller instead, in its header file? Assuming you already have a navigation controller setup in your app delegate, I'm not sure why you're pushing a nav controller - is this an image gallery feature? Or expanded image view? – Luke Aug 21 '11 at 10:44
  • Sorry Luke, that was a typo. It is indeed just pushing a VIEW controller. – NonatomicRetain Aug 21 '11 at 11:01
  • Well, you could call the other UIViewController methods such as -(void)didRotateToInterfaceOrientation in -(void)viewWillAppear (use a BOOL flag to tell if it's the first time the new view controller is being called, and not on subsequent rotations) to see if this helps. Alternatively, check out either answer here http://stackoverflow.com/questions/5023487/support-landscape-for-only-one-view-in-uinavigationcontroller . In addition, after all this, you'd need to provide some more info on how the nav controller is setup and whether it supports any orientations. – Luke Aug 21 '11 at 11:10
  • Hi Luke. Thanks very much for your time however a Googling has come up with the correct answer. If anyone else is having the same problem, I've posted the solution as a comment under the question. Thanks again Luke. – NonatomicRetain Aug 21 '11 at 11:35