TVHeaderAnimator.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // TVHeaderAnimator.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/6/20.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import ESPullToRefresh
  9. final class TVHeaderAnimator: UIView,ESRefreshProtocol,ESRefreshAnimatorProtocol {
  10. var view: UIView { return self }
  11. var insets: UIEdgeInsets = UIEdgeInsets.zero
  12. var trigger: CGFloat = 60
  13. var executeIncremental: CGFloat = 60
  14. var state: ESRefreshViewState = .pullToRefresh
  15. var duration : CGFloat = 0.5
  16. private let animationImageView = UIImageView().then{
  17. $0.image = UIImage(named:"tv_pull_loading_1")
  18. $0.animationImages = [UIImage(named:"tv_pull_loading_1")!,
  19. UIImage(named:"tv_pull_loading_2")!,
  20. UIImage(named:"tv_pull_loading_3")!,
  21. UIImage(named:"tv_pull_loading_4")!]
  22. $0.animationDuration = 0.5
  23. $0.animationRepeatCount = 0
  24. $0.contentMode = .center
  25. }
  26. override init(frame: CGRect) {
  27. super.init(frame: frame)
  28. addSubview(animationImageView)
  29. }
  30. required init?(coder aDecoder: NSCoder) {
  31. fatalError("init(coder:) has not been implemented")
  32. }
  33. func refreshAnimationBegin(view: ESRefreshComponent) {
  34. animationImageView.startAnimating()
  35. }
  36. func refreshAnimationEnd(view: ESRefreshComponent) {
  37. animationImageView.stopAnimating()
  38. }
  39. func refresh(view: ESRefreshComponent, progressDidChange progress: CGFloat) {
  40. }
  41. func refresh(view: ESRefreshComponent, stateDidChange state: ESRefreshViewState) {
  42. switch state {
  43. case .pullToRefresh://普通状态
  44. animationImageView.stopAnimating()
  45. case .releaseToRefresh: //拉到了刷新状态
  46. animationImageView.startAnimating()
  47. default:break
  48. }
  49. }
  50. override func layoutSubviews() {
  51. super.layoutSubviews()
  52. animationImageView.snp.makeConstraints({ (make) in
  53. make.center.equalToSuperview()
  54. })
  55. }
  56. }