0

Here's my scenario: I have two UIImageViews stack together (one on top of the other), something like below:

enter image description here

I want to make them visible to user only when both of them finished loading image (I am using SDWebImage with Progress View library). Before that, I need to hide both ImageView and show a progress indicator.

I want to have one progress indicator to indicate both of the two image downloading progress, but not sure how to do it.

Please share some thoughts on the approach of doing this.. Thanks!

Allan Jiang
  • 11,063
  • 27
  • 104
  • 165

1 Answers1

0

I have the same problem. Here is my solution:

    var progressArray = [CGFloat]()
    for url in urlArray {
        progressArray.append(0.0)
        var index = templateArray.indexOfObject(url)
        SDWebImageDownloader.sharedDownloader().downloadImageWithURL(url, options: nil, progress: { (receivedSize:Int, expectedSize:Int) -> Void in
            let currentProgress:CGFloat = CGFloat(receivedSize) / CGFloat(expectedSize)
            progressArray[index] = currentProgress
            var totalProgress:CGFloat = 0.0
            for progress in progressArray {
                totalProgress += progress / CGFloat(templateArray.count)
            }
            self.progressView.setProgress(Float(totalProgress), animated: true)
        }, completed: { (image, imageData, error, finished) -> Void in
            // Download complete.
            if (self.progressView.progress == 1) {
            }
        })

hope this can help someone.

JZAU
  • 3,550
  • 31
  • 37