                                 size: bounds.size,
                                 framePreloadCount: framePreloadCount,
                                 repeatCount: repeatCount)
+            animator?.delegate = self
             animator?.needsPrescaling = needsPrescaling
             animator?.prepareFramesAsynchronously()
         }

/// Protocol of `AnimatedImageView`.
public protocol AnimatedImageViewDelegate: class {
    /**
     Called after the animatedImageView has reached the max repeat count.

     - parameter imageView: The animatedImageView that is being animated.
     */
    func didFinishAnimate(for imageView: AnimatedImageView)
}

extension AnimatedImageViewDelegate {
    public func didFinishAnimate(for imageView: AnimatedImageView) {}
}

/// `AnimatedImageView` is a subclass of `UIImageView` for displaying animated image.

    fileprivate var timeSinceLastFrameChange: TimeInterval = 0.0
    fileprivate var needsPrescaling = true
    fileprivate var currentRepeatCount: UInt = 0
    fileprivate weak var delegate: AnimatorDelegate?
    
    /// Loop count of animated image.
    private var loopCount = 0
