I searched long and hard, trying to figure it out. It took about 4-5 hours before I finally managed to find a solution. I will answer my question in order to support those who come to the same problem.
So, I created the Critical Mass Typer application. This is a typed game that uses the keyboard as the main control method. Words move to the center of the screen where you have a core. You enter a word and delete the word before it reaches your core. If 4 words fall into your core, you reach a critical mass and explode (the game ends).
Now I wanted to be able to support both landscape and portrait modes in the game. I thought about it ahead of time and developed my classes so that they were easy to implement. Setting up the game for this was not a problem. Correctly rotate the submission was.
One thing that came up pretty quickly is any view that returns NO for the view controller's toAutorotateToInterfaceOrientation method will cancel the return of its subzones.
So, my main view controller (CriticalMassViewController) controls the launch / menu of the game and adds a view controller that starts game mode (CMGameViewController) as a subordinate. I want my main view manager to be in landscape mode, because if I rotate it, the animation / buttons all run sideways. I would need to create another view or change the position of everything on the screen if I wanted it to be configured for portrait mode. However, my game play should be able to switch. To accomplish this, you set the return value to the specific mode in which you want your main view to be. Then tell the game mind not to return any mode. After that, register the game presentation for notifications, then process the rotation yourself.
For example: CriticalMassViewController.m:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
CMGameViewController.m
- (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; } -(void)didRotate:(NSNotification *)nsn_notification { UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
OK, so what's going on here? My main view controller only wants to be in LandscapeRight mode. Thus, it remains so, as it is never registered for any other orientation for automatic rotation. My game view controller should be able to rotate. If I use the following code for shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
IT DOES NOT ROTATE WHEN IT HAS A CHANGE IN ORIENTATION. This is because his superview says he doesn't want to spin. As soon as the superview returns no, subview is not even asked. Therefore, instead, we, the controller of the game presentation, simply say “No,” I do not want to autorotate into any representation. Then we register a notification of a change in orientation and call our own rotation method.
These last bits of code are how you handle the rotation yourself. Call rotateView from inside didRotate. Please note: I want the user to be able to rotate after choosing the difficulty, so I have the logic inside the didRotate method to determine whether to even rotate. Comments in the code will explain why certain things happen.
-(void) rotateView:(UIInterfaceOrientation)uiio_orientation { [UIApplication sharedApplication].statusBarOrientation = uiio_orientation;
Hope this helps someone, I know that I had a very difficult time, especially the keyboard, going from landscape to portrait.