在运行时更改屏幕方向

时间:2011-04-05 14:18:02

标签: iphone ios cocos2d-iphone

我有一个开始菜单场景,我希望以纵向方向显示。游戏的其余部分处于标准横向方向。

我尝试过在场景中使用init方法:

[[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationPortrait];

[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationPortrait];

我的问题是,如何在运行时切换屏幕方向?

提前谢谢! 亚历

2 个答案:

答案 0 :(得分:1)

您需要在想要使用的视图控制器中使用以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationLandscapeLeft;
}

该代码将强制视图控制器仅以横向左侧显示。您可以返回想要支持的任何方向。

e.g。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return UIInterfaceOrientationLandscapeLeft && UIInterfaceOrientationLandscapeRight;
    }

我知道您正在使用cocos2d,但此代码在视图控制器中仍然可以正常工作。

答案 1 :(得分:0)

我不确定直接做某事.cocos2d。但是你可以将所有东西放在一个UIView中,然后对它进行90度旋转变换。有一个私有API可以强制旋转设备,但它也是应用商店规则使用它,它也是不可预测的。

相关问题