【发布时间】:2019-07-08 09:13:39
【问题描述】:
这是我绘制虚线的代码
func drawLine() {
let shapeLayer = CAShapeLayer()
shapeLayer.bounds = viewDraw.bounds
shapeLayer.position = CGPoint(x: viewDraw.bounds.width/2, y: viewDraw.bounds.height/2)
shapeLayer.fillColor = nil
shapeLayer.strokeColor = ColorConstants.ThemeColor.cgColor
shapeLayer.lineWidth = 3
shapeLayer.lineJoin = CAShapeLayerLineJoin.round // Updated in swift 4.2
shapeLayer.lineDashPattern = [10]
let path = UIBezierPath(roundedRect: viewDraw.bounds, cornerRadius: viewDraw.bounds.size.height/2)
shapeLayer.path = path.cgPath
viewDraw.layer.addSublayer(shapeLayer)
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.fromValue = 0
animation.duration = 1
shapeLayer.add(animation, forKey: "MyAnimation")
}
现在,根据我的屏幕截图,我想在虚线无限时间内将蓝点设置为红点。当蓝点到达红点时,它将以蓝点重新开始。
注意:整个屏幕是动态的,所以画线也是根据屏幕高度动态的
任何帮助将不胜感激
【问题讨论】:
标签: ios swift uibezierpath cgpoint cakeyframeanimation