Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class AnimationView: UIView {
- private let shapeLayer: CAShapeLayer = {
- let it = CAShapeLayer()
- it.fillColor = UIColor.clear.cgColor
- it.strokeColor = UIColor(hex: 0xFF598B).cgColor
- it.lineWidth = 5
- it.lineCap = .round
- it.strokeEnd = 0
- return it
- }()
- private let trackLayer: CAShapeLayer = {
- let it = CAShapeLayer()
- it.fillColor = UIColor.clear.cgColor
- it.strokeColor = UIColor(hex: 0xDDDDDD).cgColor
- it.lineWidth = 5
- it.lineCap = .round
- return it
- }()
- override func draw(_ rect: CGRect) {
- let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
- let circlePath = UIBezierPath(arcCenter: center,
- radius: 100,
- startAngle: -.pi / 2,
- endAngle: .pi * 3 / 2,
- clockwise: true)
- [trackLayer, shapeLayer].forEach { layer in
- layer.path = circlePath.cgPath
- self.layer.addSublayer(layer)
- }
- }
- func startAnimation() {
- let anim = CABasicAnimation(keyPath: "strokeEnd")
- anim.fromValue = 0
- anim.toValue = 1
- anim.duration = 1
- anim.isRemovedOnCompletion = false
- anim.fillMode = .forwards
- shapeLayer.add(anim, forKey: "key")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement