当前位置:编程学习 > wap >>

cocos2d 设置屏幕默认方向

在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)

补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,