标签:
使用命令,新创建一个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,如图所示:
再次运行,显示出来的就是竖屏了
标签:
原文地址:http://www.cnblogs.com/SkyflyBird/p/5267369.html