PQGIFImageView.swift 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // PQGIFImageView.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/9/2.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import UIKit
  9. public class PQGIFImageView: UIImageView {
  10. public var imagesDara: [String]? {
  11. didSet {
  12. generateImages()
  13. displayGIF(1, Int.max)
  14. }
  15. }
  16. public var images: [UIImage] = Array<UIImage>.init()
  17. public func generateImages() {
  18. if imagesDara != nil, (imagesDara?.count ?? 0) > 0 {
  19. for item in imagesDara! {
  20. let image = UIImage(named: item)!
  21. images.append(image)
  22. }
  23. }
  24. }
  25. public func displayGIF(_ duration: TimeInterval, _ repeatCount: Int) {
  26. if !isAnimating {
  27. layer.removeAllAnimations()
  28. if images.count <= 0 {
  29. return
  30. }
  31. animationImages = images
  32. animationDuration = duration
  33. animationRepeatCount = repeatCount
  34. startAnimating()
  35. }
  36. }
  37. }