Cocos2d-iOS中的设备方向

4

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

使用了哪个版本的cocos2d? - Guru
1个回答

1
在RootViewController.m中添加supportedInterfaceOrientations函数。
-(NSUInteger)supportedInterfaceOrientations {

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

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}

添加了那个方法,问题仍然存在。cocos2d版本相当老旧,在cocos类头文件中可以看到版权2011年的字样。我不太愿意更新它,因为这样会遇到更微妙的问题。 - Piyush-Ask Any Difference

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接