 
     override func stopAnimating() {
         if animating {
-            displayLink.removeFromRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
             displayLink.paused = true
-
             animating = false
         }
     }

////////////////////////////////////////////////////////////////////////////

private class GIFAnimatedImageView: UIImageView {
    var animatedImage: AnimatedImage?
    var animating = false
    var lastTimestampChange = CFTimeInterval(0)

    lazy var displayLink: CADisplayLink = {
        return CADisplayLink(target: self, selector: "refreshDisplay")
    }()

    var index = UInt(0) {


            //We cannot do this in the previous if/else because then some frames
            //might not be drawn
            if animateOnScroll && !refreshing && superview.contentOffset.y + topInset < 0 {
                let percentage = min(1, fabs(height) / expandedHeight)
                let count = CGFloat(imageView.animatedImage?.frameCount ?? 1) - 1
                let index = UInt(count * percentage)
