iOS 6 - Cómo ejecutar código personalizado cuando cambia la orientación
Estoy creando un juego que permite que el dispositivo esté en orientación horizontal izquierda o horizontal derecha, y el jugador puede cambiar la orientación mientras está en pausa. Cuando lo hacen, necesito cambiar la forma en que el juego interpreta el acelerómetro según la orientación.
En iOS 5 usé willRotateToInterfaceOrientation para detectar cambios y cambiar mis variables, pero eso está en desuso en iOS6. Mi código existente se ve así:
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
rect = screenRect;
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
GameEngine *engine = [GameEngine sharedEngine];
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
engine.orientation = -1;
} else {
engine.orientation = 1;
}
}
Entiendo que el reemplazo es el método viewWillLayoutSubviews en la clase UIViewController. Estoy creando este juego en cocos2d 2.1 y no parece haber una clase UIViewController en el proyecto de demostración, por lo que no tengo claro cómo incorporarlo y cómo debería verse el código para hacer que esto funcione.