【cocos2D-iphone 2.x设备方向设置】

2.x和1.x的设备方向设置有所不同,在网上找了下相关的方法,下边这个是最基本的设置方法:

原贴地址:http://120423319.blog.163.com/blog/static/278218242012102711104446/

一、

2.0开始木有1.0那套定义,那么修改横竖屏在AppDelegate.m文件中有如下代码

// Supported orientations: Landscape. Customize it for your own needs

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // 横屏可上下

return UIInterfaceOrientationIsLandscape(interfaceOrientation);

//    // 竖屏可上下

//   return UIInterfaceOrientationIsPortrait(interfaceOrientation);

//    // home键在下面

//    return ((interfaceOrientation) == UIInterfaceOrientationPortrait);

//    // home键在上面

//    return ((interfaceOrientation) == UIDeviceOrientationPortraitUpsideDown);

//    // home键在右边

//    return ((interfaceOrientation) == UIDeviceOrientationLandscapeRight);

//    // home键在左边

//    return ((interfaceOrientation) == UIDeviceOrientationLandscapeLeft);

    

}


1.0貌似可以用如下代码

[director setDeviceOrientation:kCCDeviceOrientationPortrait]; 

如果需要代码生效,请将 project-》TARGETS-》Summary-》support interface orientations 中所有的屏幕方向点击设定无效,否则代码会失效。很重要的是这里ios6实测,就算这样设定后,在一些情况下屏幕方向设定还是有BUG。


二、

如果要让设备竖直显示,HOME键朝下的话,按照上述方法设置后,其实程序还是报错,提示:

Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

接下来对如下方法进行修改:

-(NSUInteger)supportedInterfaceOrientations {

// iPhone only

if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )

return UIInterfaceOrientationMaskLandscape;

// iPad only

    return UIInterfaceOrientationMaskPortrait; //修改此处,将此处修改为UIInterfaceOrientationMaskPortrait

}

这样程序便能正常的竖直显示..

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值