SKScene iPad 高度宽度反转 [英] SKScene iPad height width reversed

查看:14
本文介绍了SKScene iPad 高度宽度反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在仅支持横向模式的 iPad 应用程序中用图块填充我的 SKScene.在场景中我检测到 h &是这样的:

I am trying to fill my SKScene with tiles, in an iPad app that only supports landscape mode. Within the scene I detect h & w as such:

int h = [UIScreen mainScreen].bounds.size.height;
int w = [UIScreen mainScreen].bounds.size.width;

不幸的是,发回的尺寸与它们需要的尺寸相反.SO在视图控制器或视图的内容中讨论这个问题有很多主题,解决方案似乎是在viewWillAppear中检测屏幕大小,而不是在viewDidLoad中.然而,这似乎不是 SKScenes 的有效解决方案.

Unfortunately, the dimensions sent back are the reverse of what they need to be. There are lots of topics in SO discussion this problem within the content of a view controller or a view, and the solution seems to be to detect screen size in viewWillAppear, not in viewDidLoad. This does not seem to be a valid solution for SKScenes, however.

有什么建议吗?

推荐答案

试试,不要用viewDidLoad,用这个

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    SKView * skView = (SKView *)self.view;
    if (!skView.scene) {
        skView.showsFPS = YES;
        skView.showsNodeCount = YES;

        SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;

        // Present the scene.
        [skView presentScene:scene];
    }
}

这篇关于SKScene iPad 高度宽度反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆