I've been using Gifu
pod in my code but it doesn't work correctly, the gif doesn't appear at all.
launchScreen image:
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.
Try using only self.imageViewGIF.animate(withGIFNamed: "mugen").