Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. func drawCircle(duration: Double, color: UIColor, clockwise: Bool) {
  2. let halfCircle: CGFloat = CGFloat(M_PI)
  3. let circle = CAShapeLayer()
  4. let rect: CGRect = CGRectMake(0, 0, 54.0, 54.0)
  5. let radius: CGFloat = rect.width/2
  6.  
  7.  
  8.  
  9. circle.path = UIBezierPath(arcCenter: CGPointMake(rect.width/2, rect.height/2), radius: radius, startAngle: 0, endAngle: halfCircle*2, clockwise: true).CGPath
  10. circle.fillColor = UIColor.clearColor().CGColor
  11. circle.strokeColor = color.CGColor
  12. circle.lineWidth = 2
  13.  
  14.  
  15. let drawAnimation: CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
  16. drawAnimation.duration = duration
  17. drawAnimation.repeatCount = 1.0
  18.  
  19. drawAnimation.fromValue = NSNumber(float: 0)
  20. drawAnimation.toValue = NSNumber(float: 1)
  21.  
  22. drawAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
  23.  
  24. circle.addAnimation(drawAnimation, forKey: "drawCircleAnimation")
  25.  
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement