ios - Cocos2d-iOS 中的设备方向

标签 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

最佳答案

在RootViewController.m中添加supportedInterfaceOrientations函数

-(NSUInteger)supportedInterfaceOrientations {

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

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}

关于ios - Cocos2d-iOS 中的设备方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922793/

相关文章:

ios - 从另一个 NSDictionary 获取 NSArray,其中包含原始键集的子集

ios - 访问 tableView 内的 UIBarBarItem 按钮 didSelectRowAtIndexPath swift

iOS 蓝牙服务

ios - Xcode 在栏按钮项目大小太大中使用 PDF 图像

iphone - ld : library not found for -lGoogleAnalytics

c - 尝试使用通过 cmake 安装的 OpenCV-2.3.1 在 XCode 中运行示例 MacOSX FaceTracker 程序

ios - 从外部委托(delegate)推送 View Controller

ios - cordova、Firebase、FCM 插件 - 不在 iOS 的通知栏中显示通知

iphone - 将 UITapGestureRecognizer 添加到 UIWebView

iPhone操作系统4.0 : Application is not coming applicationDidBecomeActive