views:

421

answers:

1

I'm writing EAGLView - based application (game) and need to add UIViewController with UIWebView in landscape mode.

What I done:

  1. Specified UIInterfaceOrientationLandscapeRight for UIInterfaceOrientation in the Info.plist

  2. Call [application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO] in the applicationDidFinishLaunching

  3. Specified shouldAutorotateToInterfaceOrientation for my ViewController class like this:

    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) orientation { 
         return [UIApplication sharedApplication].statusBarOrientation==orientation; 
    

    }

  4. Created new ViewController and add it's view into main window subview

    SViewController *VC = [[SViewController alloc] init];
    [g_EAGLView.window addSubview : VC.view];
    

(SViewController is my class derived from UIViewController)

What I have. First time I created ViewController it's displayed correctly in landscape mode. But every next times - it's displayed only in portrait mode. After placing breakpoint in the shouldAutorotateToInterfaceOrientation and examining call stack -- I noticed that internal function UIWindow::_updateToInterfaceOrientation calls only on first ViewController creation. Then I put manual call of _updateToInterfaceOrientation each time after adding subview -- and problem disappears -- every time ViewController displayed in the landscape mode. But apparently, it's wrong way to use undocumented functions. How can I cause UIWindow::_updateToInterfaceOrientation call by documented functions only ? Or maybe I missed something with landscape mode ??

Thanks a lot.

A: 

In the viewWillAppear method of your class(the one you want to be in landscape mode). Put ths line of code:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];

Hope this helps.

Thanks,

Madhup

Madhup
UIDevice doesn't have public method setOrientation.Property 'orientation' are read-only.
Newbee
ya it will give you warning but it will work.
Madhup
It will cause reject from Apple approval team :(
Newbee