开发中经常会需要UI上绘制各种各样的效果,常用的view的一些属性满足不了的,使用UIBezierPath+CAShapeLayer来绘制各种各样的视图更加方便,其他博客都有详细的使用,下面写一下最近开发中的一个效果简单实现
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 0, y: 0))
bezierPath.addLine(to: CGPoint(x: KScreenWidth-2*56, y:0 ))
let layer = CAShapeLayer()
layer.path = bezierPath.cgPath
layer.lineWidth = 2
layer.fillColor = UIColor.clear.cgColor
layer.strokeColor = UIColor.hexStringToColor(hexString: "FF5B65").cgColor
cashapeLayer = layer
self.lineView.layer.addSublayer(cashapeLayer)
//添加动画
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.fromValue = 0
animation.toValue = 1
animation.duration = 0.5
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
cashapeLayer.add(animation, forKey: "")
效果图:
QQ20180601-175332-HD.gif
使用UIBezierPath+CAShapeLayer+Animate可以方便的实现很多效果
网友评论