How to create a view controller that supports both landscape and portrait, but does not rotate between them (keeps its initial orientation)

Posted by Joshua J. McKinnon on Stack Overflow See other posts from Stack Overflow or by Joshua J. McKinnon
Published on 2011-01-05T01:45:45Z Indexed on 2011/01/05 1:54 UTC
Read the original article Hit count: 604

Filed under:
|
|

I want to create a view controller that supports both landscape and portrait orientations, but that can not rotate between them - that is, the view should retain its original orientation.

I have tried creating an ivar initialOrientation and setting it in -viewDidAppear with

initialOrientation = self.interfaceOrientation;

then

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == initialOrientation);
}

But that causes confusing problems (presumably because -shouldAutorotateToInterfaceOrientation is called before -viewDidAppear).

How can I lock the orientation to its original orientation?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios