Cocos2d-iOS中的设备方向

时间:2015-11-25 17:24:56

标签: ios objective-c xcode cocos2d-iphone

Xcode:7.1,运行于:iPhone 6s Plus

我的AppDelegate.mm有以下代码:

- (void) applicationDidFinishLaunching:(UIApplication*)application
---------some code
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
     NSLog(@"if");
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#else
          NSLog(@"else");
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#endif
---------somecode

我的GameConfig.h有:

#define GAME_AUTOROTATION kGameAutorotationUIViewController

我的RootViewController.m有:

if GAME_AUTOROTATION == kGameAutorotationUIViewController
    return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

我的Xcode设置是: enter image description here

虽然设备方向转向横向,但游戏仍然以纵向显示。游戏截图如下: enter image description here

1 个答案:

答案 0 :(得分:1)

在RootViewController.m中添加supportedInterfaceOrientations函数

-(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskLandscape;

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}