圆不是在视图中心绘制

因此,我试图在UIView的中心绘制一个圆。

class CircleView: UIView {

let shapeLayer = CAShapeLayer()

override func draw(_ rect: CGRect) {

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

    shapeLayer.path         = circularPath.cgPath
    shapeLayer.strokeColor  = Colors.darkPurple.cgColor
    shapeLayer.fillColor    = UIColor.white.cgColor
    shapeLayer.lineWidth    = 10
    shapeLayer.strokeEnd    = 0

    layer.addSublayer(shapeLayer)

    addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap)))
}

@objc private func handleTap() {
    print("....Animating Circle....")

    let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
    basicAnimation.toValue               = 1
    basicAnimation.duration              = 2
    basicAnimation.fillMode              = .forwards
    basicAnimation.isRemovedOnCompletion = false

    shapeLayer.add(basicAnimation, forKey: "circleAnimation")
}

}

但是,即使我已指定arcCenter为视图的中心,由于某种原因,圆仍被完全绘制在视图的右下角。

enter image description here