这看起来应该是显而易见的,但这对我来说并不像你最初想的那样令人困惑。
Cocos2d模板的GameConfig.h我设置了以下内容:
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationNone
// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone
// Ignore this value on Mac
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
#else
#error(unknown architecture)
#endif
在App Delegate applicationDidFinishLaunching
中,我有:
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
在RootViewController中shouldAutorotateToInterfaceOrientation
:
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
尽管kGameAutorotationNone
的所有条件都设置为UIInterfaceOrientationLandscapeLeft
,但我看到了什么?的画像。
奇怪的是,如果我改为shouldAutorotateToInterfaceOrientation
,我可以看到左侧风景:
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait);
任何人都可以帮我理解这里发生了什么吗?
答案 0 :(得分:0)
您所看到的效果来自于为横向方向切换设备和界面方向这一事实:
UIInterfaceOrientationLandscapeLeft == UIDeviceOrientationLandscapeRight
UIInterfaceOrientationLandscapeRight == UIDeviceOrientationLandscapeLeft
这意味着您的设备方向是LandscapeLeft,但您不允许RootViewController旋转到接口方向LandscapeRight。因此它将默认为纵向模式。我想如果您将设备旋转180°,它会突然旋转到设备方向LandscapeRight。
顺便说一下,当您更改GameConfig.h中的自动旋转设置时,您无需对RootViewController类进行任何更改。