Mac cocos2d-x 3.8 设置横屏/竖屏

新创建cocos2d-lua的项目,名为Demo,命令:

cocos new Demo -p com.demo.org -l lua -d /Users/用户名/Documents/cocos2d-x-3.8.1/projects

创建成功后,然后使用Xcode打开项目:

../projects/Demo/frameworks/runtime-src/proj.ios_mac/Demo.xcodeproj

运行项目,发现是横屏的窗口,然而,我想要竖屏的窗口,其实现步骤如下:

(1) 打开ios/RootViewController.mm,如图所示:

修改函数一:

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
// Portrait 纵向, Landscape 横向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (SimpleConfigParser::getInstance()->isLanscape()) { return UIInterfaceOrientationIsLandscape( interfaceOrientation ); }else{ return UIInterfaceOrientationIsPortrait( interfaceOrientation ); } }

根据个人需求,可将其改为,如:return UIInterfaceOrientationIsPortrait( interfaceOrientation );

修改函数二:

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    if (SimpleConfigParser::getInstance()->isLanscape()) {
        // 横向
        return UIInterfaceOrientationMaskLandscape;
    }else{
        // 纵向
        return UIInterfaceOrientationMaskPortrait;
    }
#endif
}

根据个人需求,可将其修改为,如: return UIInterfaceOrientationMaskPortrait;

修改函数三:

// 是否支持屏幕旋转
- (BOOL) shouldAutorotate {
    if (SimpleConfigParser::getInstance()->isLanscape()) {
        return YES;
    }else{
        return NO;
    }
}

根据个人需求,可将其修改为,如: return NO;

(2) 修改完代码后,接下来最关键的一点是,点击项目Demo, 选择General, 将其Deployment Info 下的Device Orientation 仅勾选上

Portrait,如图所示:

再次运行,显示出来的就是竖屏了

 

posted @ 2016-03-11 21:53  Code~  阅读(907)  评论(0编辑  收藏  举报