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,如图所示:

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

 

转载于:https://www.cnblogs.com/SkyflyBird/p/5267369.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值