0

I've been using Gifu pod in my code but it doesn't work correctly, the gif doesn't appear at all.

launchScreen image:

enter image description here

LaunchScreen code:

import UIKit
import Gifu

class LaunchScreenViewController: UIViewController {


@IBOutlet weak var imageViewGIF: GIFImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.isHidden = true
    animate()
    
}


func animate() {
    imageViewGIF.prepareForAnimation(withGIFNamed: "animatedTick.gif", loopCount: 1)
    self.imageViewGIF.animate(withGIFNamed: "mugen")
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
        self.imageViewGIF.startAnimatingGIF()
        DispatchQueue.global().asyncAfter(deadline: .now() + 0.5 + self.imageViewGIF.gifLoopDuration, execute: {
            
        })
        let loginViewController = self.storyboard!.instantiateViewController(identifier: "LoginViewController")
        self.navigationController?.pushViewController(loginViewController, animated: true)
    }
    
}
}

UIImageViewExtension.swift code

import UIKit
import Gifu

extension UIImageView: GIFAnimatable {
  private struct AssociatedKeys {
    static var AnimatorKey = "gifu.animator.key"
  }

  override open func display(_ layer: CALayer) {
    updateImageIfNeeded()
  }

  public var animator: Animator? {
    get {
      guard let animator = objc_getAssociatedObject(self, &AssociatedKeys.AnimatorKey) as? Animator else {
        let animator = Animator(withDelegate: self)
        self.animator = animator
        return animator
      }

      return animator
    }

    set {
      objc_setAssociatedObject(self, &AssociatedKeys.AnimatorKey, newValue as Animator?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
    }
  }
}

Note that the main LaunchScreen file is still the same and I didn't change anything in it, I was trying only to create custom file.

Menaim
  • 937
  • 7
  • 28

1 Answers1

0

Try using only self.imageViewGIF.animate(withGIFNamed: "mugen").

Akilan C B
  • 199
  • 1
  • 9