i use this SwiftGif library. I put some gif into UIImageView. This is my code:
dispatch_async(dispatch_get_main_queue(),{
self.img1.image=UIImage.gifWithURL("http://mywebsite/img1.gif")
self.img2.image=UIImage.gifWithURL("http://mywebsite/img2.gif")
self.img3.image=UIImage.gifWithURL("http://mywebsite/img1.gif")
})
The gifs are shown correctly but the animation is slow. How can I fix this? Thanks!
Paste the following code in UIImage+Gif.swift
where calculation of duration is done in in animatedImageWithSource
function:
// Calculate full duration
let duration: Int = {
var sum:Double = 0
for val: Int in delays {
let newVal = Double(val) - (Double(val)/1.5)//Modified calculation to speed up the animtion in gif
//sum += val :default calculation
sum += newVal
}
return Int(sum)
}()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With