Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 快速定位_Ios_Swift_Sprite Kit - Fatal编程技术网

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。您的场景与视图的大小不同可能会重复