我有一个开始菜单场景,我想以纵向方向显示它。游戏的其余部分是标准横向方向。
我在场景初始化方法中尝试了以下方法:
[[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationPortrait];
和
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationPortrait];
我的问题是,如何在运行时切换屏幕方向?
提前致谢! 亚历克斯
最佳答案
您需要在想要横向显示的 View Controller 中使用以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationLandscapeLeft;
}
该代码将强制 View Controller 仅以横向左方式显示。您可以返回您想要支持的任何方向。
例如
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationLandscapeLeft && UIInterfaceOrientationLandscapeRight;
}
我知道您正在使用 cocos2d,但这段代码在您的 View Controller 中应该仍然可以正常工作。
关于iphone - 在运行时更改屏幕方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5553360/