【问题标题】:Centering a UIBezierPath居中 UIBezierPath
【发布时间】:2017-08-31 04:15:37
【问题描述】:

我有一个圆角正方形的 UIBezierPath。它有点像这样:

这是我的形状代码:

let shape = SKShapeNode()
    shape.path = UIBezierPath(roundedRect: CGRect(x:(0), y: (0), width: (250), height: (400)), cornerRadius: 64).cgPath
    shape.position = CGPoint(x: 0, y: 0)
    print(shape.position)
    shape.fillColor = UIColor.white
    shape.strokeColor = UIColor.white
    shape.lineWidth = 5
    addChild(shape)

我想把它放在屏幕中间,但是使用

shape.position = CGPoint(x: self.frame.width, y: self.frame.height)

不起作用。谢谢!

【问题讨论】:

    标签: swift swift3 sprite-kit uibezierpath


    【解决方案1】:

    我建议您将 UIBezierPath 置于形状节点的中心。例如,

    let width:CGFloat = 250
    let height:CGFloat = 400
    shape.path = UIBezierPath(roundedRect: CGRect(x:-width/2, y: -height/2, width: width, height: height), cornerRadius: 64).cgPath
    

    您可以通过将形状的位置设置为 (0, 0) 在场景中居中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多