我正在创建一个游戏,允许设备处于横向左或右方向,并且玩家可以在暂停时更改方向。当他们这样做时,我需要根据方向更改游戏对加速度计的解释方式。
在iOS 5中,我使用willRotateToInterfaceOrientation来捕获更改并更改我的变量,但在iOS6中已经被弃用。 我现有的代码如下:
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;
}
}
我知道替代方法是UIViewController类中的viewWillLayoutSubviews方法。 我正在使用cocos2d 2.1构建此游戏,并且演示项目中似乎没有UIViewController类,因此我不清楚如何将其合并以及代码应该看起来如何才能使其工作。
UIInterfaceOrientation
和UIDeviceOrientation
之间的区别。 - Till