0

I'm making an iOS application that has an interface in the portrait view.

However, when displaying web content I want the view to display in a landscape format, because I want the website test to display larger initially without the user needing to zoom.

Can I tell the program so present this view only in landscape?

Thank you.

dgund
  • 3,459
  • 4
  • 39
  • 64

1 Answers1

1

looks like you want to force the orientation to landscape mode only..
heres my solution in MyViewController.h
add this code on top of MyViewController's @interface

 //force orientation on device
    @interface UIDevice (PrivateOrientation)
    - (void) setOrientation:(UIInterfaceOrientation)orientation;
    @end

then in the implementation file (MyViewController.m) add this code inside viewWillAppear:

//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];

this will force the device orientation to landscape mode left (or right depending what you want)
if you want to go back to portrait mode after leaving the viewcontroller add this code inside viewWillDisappear:

//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

finally implement shouldAutorotateToInterfaceOrientation: to force the view into landscape mode left or right (or both)

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

hope this helps :3

otakuProgrammer
  • 298
  • 2
  • 12
  • Would my app be rejected from the App Store for this? – dgund Jan 19 '12 at 21:43
  • i think you may find this topic helpful [here](http://stackoverflow.com/questions/5030315/how-to-constrain-autorotation-to-a-single-orientation-for-some-views-while-allo) and [here](http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation) i cant say its 100% acceptable, based on what they mentioned [here](http://stackoverflow.com/questions/7280464/device-orientation-change-in-legal-way-ios-4-0) > there's no way to force a device orientation and get your application approved by Apple. – otakuProgrammer Jan 20 '12 at 03:45
  • I need to get it approved by Apple, but thanks. I'll accept your answer. – dgund Jan 20 '12 at 21:33