I have three ViewControllers configured to handle three views. The problem I am facing is that in the simulator the orientation is LandscapeRight (which is exactly what I want) and the first view is displayed correctly in this landscape view, but when I switch to the second and third views, they appear rotated to 90 degrees counterclockwise with the upper left viewing angle in the lower left corner of the phone screen. I tried to debug this for a few days, and the closest I realized is tracking it like this:
In the appDidFinishLaunching app, the following:
NSLog(@"1"); [window addSubview:welcomeController.view]; NSLog(@"2"); [window addSubview:goalController.view]; NSLog(@"3"); [window addSubview:planningController.view]; NSLog(@"4"); [window bringSubviewToFront:welcomeController.view]; NSLog(@"5");
Each of my ViewControllers implements something similar to the following (the only change is the name of the controller, which is disabled on the line passed to NSLog):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations NSLog(@"called for WelcomeController"); return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
With this, I get the following output on the console:
a called for WelcomeController called for WelcomeController called for WelcomeController called for WelcomeController 2 called for GoalController 3 called for PlanningController 4 5
I'm curious that shouldAutorotateToInterfaceOrientation is called 4 times for the first view added, while the other two are called only once. I expect that this is probably due to the fact that you need to do some tuning first (and I believe that the simulator runs in portrait mode, so it can cause it when performing a rotation), but I find the correlation a bit suspicious.
I switched the order around, so addSubview is called for firstController and secondController. In this case, it is the goalController, which is displayed in the correct landscape orientation (usually it is the receiving controller). It would seem that this excludes my XIB files and ViewControllers themselves. I'm not sure why the first view where addSubview is called is special. I also tried using insertSubview at index 0 with the same results.
iphone cocoa-touch
Brian Underwood Sep 27 '09 at 23:38 2009-09-27 23:38
source share