Question

I'm trying to build an iPhone application that has two subviews in the main window. Each view has its own UIViewController subclass associated with it. Also, within each controller's implementation, I've added the following method:

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

Thus, I would expect both of the views to respond to changes in orientation. However, this is not the case. Only the first view added to the app's main window responds to orientation. (If I swap the order the views are added, then only the other view responds. In other words, either will work--but only one at a time.)

Why is this? Is it not possible to handle the orientation changes of more than one view?

Thanks!

EDIT: Someone else had this question, so I'm copying my solution here:

I was able to address this issue by providing a root view and a root view controller with the method "shouldAutoRotate..." and adding my other views as subviews to the root view. The subviews inherit the auto-rotating behavior, and their associated view controllers shouldn't need to override "shouldAutoRotate..."

Was it helpful?

Solution 2

Finally going to post my solution here:

Basically, it came down to having a "root" UIViewController. In this, I have the method:

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

I also added the views I wanted to auto-rotate as subviews to this root UIViewContoller's UIView. These subviews also have view controllers but do not override shouldAutorotateToInterfaceOrientation. In fact, adding this method to those view controllers seems to have no effect whatsoever. Only the root view contoller's shouldAutorotateToInterfaceOrientation seems to work and all subviews get rotated properly.

OTHER TIPS

You need to override the shouldAutorotateToInterfaceOrientation method on all three controllers you have.

you can try to implement this method in the class, which view contains both your viewController's views

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top