如何移动形状层的位置(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)

相关内容

  • 没有找到相关文章

最新更新