ActivityIndicatorAnimationSemiCircleSpin.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // Created by Tom Baranes on 23/08/16.
  3. // Copyright (c) 2016 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. public class ActivityIndicatorAnimationSemiCircleSpin: ActivityIndicatorAnimating {
  7. // MARK: Properties
  8. fileprivate let duration: CFTimeInterval = 0.6
  9. // MARK: ActivityIndicatorAnimating
  10. public func configureAnimation(in layer: CALayer, size: CGSize, color: UIColor) {
  11. let circle = ActivityIndicatorShape.circleSemi.makeLayer(size: size, color: color)
  12. let frame = CGRect(
  13. x: (layer.bounds.width - size.width) / 2,
  14. y: (layer.bounds.height - size.height) / 2,
  15. width: size.width,
  16. height: size.height
  17. )
  18. circle.frame = frame
  19. circle.add(defaultAnimation, forKey: "animation")
  20. layer.addSublayer(circle)
  21. }
  22. }
  23. // MARK: - Setup
  24. private extension ActivityIndicatorAnimationSemiCircleSpin {
  25. var defaultAnimation: CAKeyframeAnimation {
  26. let animation = CAKeyframeAnimation(keyPath: .rotationZ)
  27. animation.keyTimes = [0, 0.5, 1]
  28. animation.values = [0, CGFloat.pi, 2 * CGFloat.pi]
  29. animation.duration = duration
  30. animation.repeatCount = .infinity
  31. animation.isRemovedOnCompletion = false
  32. return animation
  33. }
  34. }