Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow gif animation with SwiftGif

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!

like image 555
Matteo Serpentoni Avatar asked Jan 05 '23 22:01

Matteo Serpentoni


1 Answers

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)
    }()
like image 163
MahammedAsif Avatar answered Jan 15 '23 12:01

MahammedAsif