views:

121

answers:

2

Yet another landscape mode question.

We've all seen the

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

Nonsense. I have not been able to get this to work on the simulator or on the device.

What I get is this:

http://i47.tinypic.com/zl9egh.png

when I really want this:

http://i45.tinypic.com/xms6cm.png

As you might be able to tell, it's flipping the phone but it's not realizing it has been flipped.

I've seen the hidden method

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

But I need this app to be on the app store, and I don't know if they will crack down on that.

Does anyone have any idea on how to get this damn thing to straighten itself out?

+1  A: 

Ideally your view controller should implement:

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

Then the only allowed orientation for that view controller is one of the landscape orientations.

Unless you have a pretty complex view hierarchy that utilizes a tab bar controller, this should cause the view to rotate when it's pushed.

If it doesn't work you can try:

[[UIDevice currentDevice] performSelector:
                               @selector(setOrientation:) 
                           withObject:(id)UIInterfaceOrientationLandscapeRight];

I have an app in the AppStore that uses this code because in my case I do have a complex hierarchy of views that keeps the one I need to be landscape only from working.

Matt Long
This does address one issue of erroniously flipping back to a portrait view. However my major problem is the initial load. When it is pushed it ends up in portrait mode.I'm putting the statusbar code in the viewDidLoad of my target view controller... should I put it elsewhere?
Jasconius
A: 

If you want to rotate a single part of the app you can use the CGAffineTransform transform property of a UIView. For an example check this thread:

http://stackoverflow.com/questions/347721/uiview-perspective-transform

David Sowsy