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?
I was on the right track, I guess. I solved this by making
initialOrientationa property, then setting it from the calling viewController:Now I have, in
OrientationLockedViewController