How to create a view controller that supports both landscape and portrait, but does not rotate between them (keeps its initial orientation)
- by Joshua J. McKinnon
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?