cocos2d 设置屏幕默认方向

来源:未知 责任编辑:智问网络 发表时间:2013-08-28 11:57 点击:

在cocos2d创建的新工程运行结果屏幕都是横向,控制代码

[cpp] 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
     


这段代码控制的是屏幕视图默认横向显示;

还有一个需要区别的是硬件设备方向(灰黑色背景表示被选择,所支持方向)


当你旋转设备方向时候,发现当屏幕竖着的时候,视图里面内容并未调整,标签HelloWord并未横着放

 


  

如果想让运行时候默认竖屏,修改代码返回值(或者 return YES;也行)
[cpp] 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

//  return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 

设备支持方向前两个必选,后面两个看需要,需要的话也可以选上;


 UIInterfaceOrientationIsPortrait和UIInterfaceOrientationIsLandscape在UIApplication.h文件中宏定义

#define UIInterfaceOrientationIsPortrait(orientation)  ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown)

#define UIInterfaceOrientationIsLandscape(orientation) ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight)

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • cocos2d-x学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1