ActivityIndicatorAnimationHeartBeat.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // ActivityIndicatorAnimationHeartBeat.swift
  3. // IBAnimatable
  4. //
  5. // Created by phimage on 02/05/2018.
  6. // Copyright © 2018 IBAnimatable. All rights reserved.
  7. //
  8. import UIKit
  9. public class ActivityIndicatorAnimationHeartBeat: ActivityIndicatorAnimating {
  10. // MARK: Properties
  11. fileprivate let duration: CFTimeInterval = 0.8
  12. // MARK: ActivityIndicatorAnimating
  13. public func configureAnimation(in layer: CALayer, size: CGSize, color: UIColor) {
  14. let x = (layer.bounds.size.width - size.width) / 2
  15. let y = (layer.bounds.size.height - size.height) / 2
  16. let circle = ActivityIndicatorShape.mask(type: .heart).makeLayer(size: size, color: color)
  17. circle.frame = CGRect(x: x, y: y, width: size.width, height: size.height)
  18. circle.add(defaultAnimation, forKey: "animation")
  19. layer.addSublayer(circle)
  20. }
  21. }
  22. // MARK: - Setup
  23. private extension ActivityIndicatorAnimationHeartBeat {
  24. var defaultAnimation: CABasicAnimation {
  25. let scaleAnimation = CABasicAnimation(keyPath: .scale)
  26. scaleAnimation.timingFunctionType = .easeOutBack
  27. scaleAnimation.duration = duration
  28. scaleAnimation.repeatCount = .infinity
  29. scaleAnimation.autoreverses = true
  30. scaleAnimation.fromValue = 1
  31. scaleAnimation.toValue = 0.8
  32. scaleAnimation.isRemovedOnCompletion = false
  33. return scaleAnimation
  34. }
  35. }