Ios 快速定位
如何将彩色条的位置设置到屏幕底部 我有以下几行:Ios 快速定位,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,如何将彩色条的位置设置到屏幕底部 我有以下几行: let ground = SKSpriteNode(color: UIColor(red: 144/255, green: 100/255, blue: 144/255, alpha: 1.0) , size: CGSize(width: view.frame.size.width, height: 20)) ground.position = ??? addChild(ground) 这应该起作用: let ground = SKSprite
let ground = SKSpriteNode(color: UIColor(red: 144/255, green: 100/255,
blue: 144/255, alpha: 1.0) , size: CGSize(width: view.frame.size.width, height: 20))
ground.position = ???
addChild(ground)
这应该起作用:
let ground = SKSpriteNode(color: UIColor(red: 144/255, green: 100/255,
blue: 144/255, alpha: 1.0) , size: CGSize(width: self.size.width, height: 20))
ground.anchorPoint = CGPoint(x: 0, y: 0)
ground.position = CGPoint(x: 0,y: 0)
addChild(ground)
可能的陷阱:
如果发生方向更改,则必须重新定位。还要确保场景没有屏幕那么大 尝试以下代码行:
let ground = SKSpriteNode(color: UIColor(red: 144/255, green: 100/255,
blue: 144/255, alpha: 1.0) , size: CGSize(width: view.frame.size.width, height: 20))
view.addSubview(ground)
ground.leftAnchor.constraintEqualToAnchor(view.leftAnchor).active = true
ground.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor).active = true
ground.widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
ground.heightAnchor.constraintEqualToConstant(40).active = true
这取决于设备方向,如果对视图控制器进行了任何修改,则必须使用场景maxY或minY。您的场景与视图的大小不同可能会重复