iphone - 在运行时更改屏幕方向

标签 iphone ios cocos2d-iphone

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

我在场景初始化方法中尝试了以下方法:

[[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/

相关文章:

iphone - UICollectionView:以编程方式查看标题

ios - 将应用内购买添加到 Open Feint 支持的游戏中

ios - 将等距平铺 map 坐标转换为屏幕坐标

iphone - 我使用 SD 图像构建我的应用程序,如何支持 HD?

ios - 未调用 subview 手势识别器

iPhone iOS 使用函数从 CoreData 检索 NSMutableArray

iphone - 通过 Xcode 安装 iOS IPA,钥匙串(keychain)中没有证书,也没有安装配置文件

ios - Swift - addTarget() 不与 addSubview() 一起使用

ios - 如何在没有 Cocoapods 的情况下手动将包添加到 Swift

ios - 为什么会出现未捕获的异常?