UIViewController+NetAnimation.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // UIViewController+NetAnimation.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/9/4.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIViewController {
  10. func showLoadingAnimation(superView: UIView) {
  11. if let existView = superView.subviews.filter({ $0.isKind(of: NetAnimationView.self) }).first as? NetAnimationView {
  12. existView.removeFromSuperview()
  13. }
  14. let animationView = NetAnimationView(animationType: .loading)
  15. superView.addSubview(animationView)
  16. superView.bringSubviewToFront(animationView)
  17. animationView.snp.makeConstraints { (make) in
  18. make.width.equalTo(200)
  19. make.height.equalTo(220)
  20. make.centerX.equalToSuperview()
  21. make.centerY.equalToSuperview()
  22. }
  23. animationView.startAnimation(animationType:.loading)
  24. }
  25. func hideLoadingAnimation(superView: UIView) {
  26. guard let animationView = superView.subviews.filter({ $0.isKind(of: NetAnimationView.self) }).first as? NetAnimationView else { return }
  27. animationView.stopAnimation(animationType:.loading)
  28. animationView.removeFromSuperview()
  29. }
  30. }