【问题标题】:Device orientation in Cocos2d-iOSCocos2d-iOS 中的设备方向
【发布时间】:2015-11-25 17:24:56
【问题描述】:

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 设置是:

虽然设备方向为横向,但游戏仍以纵向显示。游戏截图如下:

【问题讨论】:

  • 使用了哪个cocos2d版本?

标签: ios objective-c xcode cocos2d-iphone


【解决方案1】:

在RootViewController.m中添加supportedInterfaceOrientations函数

-(NSUInteger)supportedInterfaceOrientations {

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

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}

【讨论】:

  • 添加该方法仍然是相同的问题。 cocos2d 版本比较老了。在 cocos 类标题中,我可以看到版权 2011。我不愿意更新它,因为我会遇到更微妙的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-10
  • 1970-01-01
  • 2014-10-28
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多