当前位置 : 主页 > 手机开发 > 其它 >

Cocos2d-iOS中的设备方向

来源:互联网 收集:自由互联 发布时间:2021-06-13
Xcode:7.1,运行于:iPhone 6s Plus 我的AppDelegate.mm有以下代码: - (void) applicationDidFinishLaunching:(UIApplication*)application---------some code#if GAME_AUTOROTATION == kGameAutorotationUIViewController NSLog(@"if"); [dire
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设置是:

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

在RootViewController.m中添加supportedInterfaceOrientations函数

-(NSUInteger)supportedInterfaceOrientations {

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

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}
网友评论