如何移动形状层的位置(swift4)

how to move position of shape layer (swift4)

我的代码现在使用圆形进度视图,它位于屏幕的正中央。我需要这个精确的圆形进度视图以沿 x 轴向下移动大约 150 像素。

import UIKit

class ViewController: UIViewController {




    let shapeLayer = CAShapeLayer()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
           let center = view.center
        let trackLayer = CAShapeLayer()

              let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)

        trackLayer.path = circularPath.cgPath
        trackLayer.strokeColor = UIColor.lightGray.cgColor
        trackLayer.lineWidth = 10

        trackLayer.fillColor = UIColor.clear.cgColor
        trackLayer.lineCap = kCALineCapRound
        view.layer.addSublayer(trackLayer)




        shapeLayer.path = circularPath.cgPath

        shapeLayer.strokeColor = UIColor.red.cgColor
        shapeLayer.lineWidth = 10

        shapeLayer.fillColor = UIColor.clear.cgColor
        shapeLayer.lineCap = kCALineCapRound

        shapeLayer.strokeEnd = 0


        view.layer.addSublayer(shapeLayer)
    }

你可以试试,你说下来Y

let center = CGPoint(x:view.center.x,y:view.center.y + 150)

或对x

let center = CGPoint(x:view.center.x + 150 ,y:view.center.y)