Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. final class AnimationView: UIView {
  2. private let shapeLayer: CAShapeLayer = {
  3. let it = CAShapeLayer()
  4. it.fillColor = UIColor.clear.cgColor
  5. it.strokeColor = UIColor(hex: 0xFF598B).cgColor
  6. it.lineWidth = 5
  7. it.lineCap = .round
  8. it.strokeEnd = 0
  9. return it
  10. }()
  11.  
  12. private let trackLayer: CAShapeLayer = {
  13. let it = CAShapeLayer()
  14. it.fillColor = UIColor.clear.cgColor
  15. it.strokeColor = UIColor(hex: 0xDDDDDD).cgColor
  16. it.lineWidth = 5
  17. it.lineCap = .round
  18. return it
  19. }()
  20.  
  21. override func draw(_ rect: CGRect) {
  22. let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
  23.  
  24. let circlePath = UIBezierPath(arcCenter: center,
  25. radius: 100,
  26. startAngle: -.pi / 2,
  27. endAngle: .pi * 3 / 2,
  28. clockwise: true)
  29.  
  30. [trackLayer, shapeLayer].forEach { layer in
  31. layer.path = circlePath.cgPath
  32. self.layer.addSublayer(layer)
  33. }
  34. }
  35.  
  36. func startAnimation() {
  37. let anim = CABasicAnimation(keyPath: "strokeEnd")
  38. anim.fromValue = 0
  39. anim.toValue = 1
  40. anim.duration = 1
  41. anim.isRemovedOnCompletion = false
  42. anim.fillMode = .forwards
  43. shapeLayer.add(anim, forKey: "key")
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement