我正在按照Splash Screen中的以下代码在UIImageView中设置GIF。
let url = Bundle.main.url(forResource: "Splash", withExtension: "gif")
self.imgGifSplash.sd_setImage(with: url!, completed: { (img, error, type, url) in
// this block is called when Gif is loaded in UIImageView, not when image is completed playing once.
DispatchQueue.main.asyncAfter(deadline: .now() + 3.2) { // Change `2.0` to the desired number of seconds.
if let _ = UserData.shared.loginData?.token {
let VC = mainStoryboard.instantiateViewController(withIdentifier: "HomeVCNav") as! UINavigationController
objAppDelegate.window?.rootViewController = VC
}
else
{
let VC = mainStoryboard.instantiateViewController(withIdentifier: "LoginNav") as! UINavigationController
objAppDelegate.window?.rootViewController = VC
}
}
}
我希望Gif只播放一次。所以我尝试使用3.2秒的计时器,但是当我使用不同的设备时,我得到了不同的结果,例如有时它只播放一次,有时播放两次,有时甚至不播放一次。
我如何获得一个只播放一次GIF的完美动画启动画面?
希望得到完美的答案。预先感谢。