【发布时间】:2021-05-16 22:29:40
【问题描述】:
我一直在我的代码中使用Gifu pod,但它不能正常工作,gif 根本没有出现。
启动屏幕图片:
启动屏幕代码:
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 代码
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)
}
}
}
请注意,主 LaunchScreen 文件仍然相同,我没有更改其中的任何内容,我只是尝试创建自定义文件。
【问题讨论】:
-
澄清一下,这个视图控制器是你的主故事板的入口点场景?你设置断点了吗?
viewDidLoad甚至被调用了吗? -
是的,它被调用了,它显示了 imageView 但没有显示其中的 GIF
标签: ios xcode swift5 animated-gif ios-animations