【问题标题】:Label in SKScene not fully left justified in iPhone 6 / 6plusSKScene 中的标签在 iPhone 6 / 6plus 中未完全左对齐
【发布时间】:2015-12-29 01:02:01
【问题描述】:

我正在努力确保标签始终出现在屏幕的左上角,无论使用什么设备。

这是我的代码:

override func didMoveToView(view: SKView) {

        var screenSize = UIScreen.mainScreen().bounds
        var screenWidth = screenSize.width
        var screenHeight = screenSize.height


        self.scaleMode = SKSceneScaleMode.AspectFit;
        self.backgroundColor = SKColor.blackColor()
        gameScore = SKLabelNode(fontNamed: "Chalkduster")
        gameScore.text = "Score: 0"
        gameScore.position = CGPointMake(0, self.frame.size.height)
        gameScore.horizontalAlignmentMode = .Left
        gameScore.verticalAlignmentMode = .Top
        gameScore.fontSize = 48
        gameScore.zPosition = 1
        addChild(gameScore)


    }

在所有 iPad 系列设备上,它完美地显示在左侧,但在 iPhone 6 和 6+ 上,它显示为向右缩进约 1/2 英寸。

任何想法为什么会这样?

谢谢!

【问题讨论】:

    标签: ios swift sprite-kit skscene


    【解决方案1】:

    我想回答这个问题,以防像我这样的其他初学者遇到困难! 请务必阅读宽高比和缩放模式。

    我有:

    self.scaleMode = SKSceneScaleMode.AspectFit;
    

    但应该是:

     self.scaleMode = SKSceneScaleMode.Fill;
    

    【讨论】:

    • 您在技术上也不想要,您将场景大小设置为视图大小,因此您需要 self.scaleMode = .ResizeFill; 否则您的场景大小将等于应用自动约束之前的视图(即为什么它在 iPad 和 iPhone 上看起来不同)。使用 Resize Fill,它总是使场景与视图一样大小,因此您不必担心
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2017-05-06
    • 2012-04-07
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    相关资源
    最近更新 更多