Ios 无法在我的应用程序中使用Gifu Pod“;GIF不';“不出现”;
我一直在我的代码中使用Ios 无法在我的应用程序中使用Gifu Pod“;GIF不';“不出现”;,ios,xcode,swift5,animated-gif,ios-animations,Ios,Xcode,Swift5,Animated Gif,Ios Animations,我一直在我的代码中使用Gifupod,但它工作不正常,gif根本不显示 启动屏幕图像: import UIKit import Gifu class LaunchScreenViewController: UIViewController { @IBOutlet weak var imageViewGIF: GIFImageView! override func viewDidLoad() { super.viewDidLoad() self.navigationCont
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)
}
}
}
启动屏幕代码:
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)
}
}
}
请注意,主启动屏幕文件仍然是相同的,我没有更改其中的任何内容,我只是尝试创建自定义文件
只是澄清一下,这个视图控制器是主情节提要中的入口点场景吗?你设置断点了吗?
viewDidLoad
是否被调用?是的,它被调用并显示图像视图,但不显示其中的GIF