xcode 4.5中Cocos2d 屏幕方向问题

由于设备升级到了ios6的系统,所以为了调试,xcode也升级到了4.5,但是,当我运行以前的cocos2d工程的时候,发现本来是横屏的游戏,变成了竖屏,而且新建的cocos2d工程也是有这个问题。

所以经过一系列的调试,修改,查阅文档。发现最新的帮助文档里面写到:

In iOS 6, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Generally, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen。

上面红色着重标记了一下关键字。大概意思也就是在ios6中,一般是在Info.plist里面来设置这个app需要的方向,或者重写 supportedInterfaceOrientations这个方法,而且为了系统能够调用这些东西,你需要设置这个view controller是这个window的root view controller或者弹出充满整个屏幕这个一个view controller。而在coocos2d模板创建的工程当中使用的是:

[window addSubview: viewController.view];

所以我们怎么设置Info.plist都是没有用的。而且view controller官方文档直接写明了:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0);

这个shouldAutorotateToInterfaceOrientation在ios6中被弃用了,所以在RootViewController.m中这个函数怎么都不会被调用了。

不过在这个类里面还有一个

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

不过经过测试也发现没有被调用。

 

这个时候,你要是把addsubview那句改成:

[window setRootViewController:viewController];

这个时候,你就可以发现你的cocos2d工程恢复了正常了,而且willRotateToInterfaceOrientation也被调用了。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值