Hide UIProgressView after fetching for PHAsset is complete and progress is complete

I am fulfilling a request for a given image resource PHAsset, and I am using UIProgressViewit to indicate progress with the help progressHandler PHImageRequestOptionsthat I can provide. When this handler is called, it provides me progress, so I set progress in representing progress, but I also animate this new progress through setProgress:animated:. Now I need to figure out how to hide the progress as soon as the progress reaches 1.0, but only after it has completed the animation before 1.0.

For example, it can start loading an asset, call a progress callback with 0.2, then the next callback can be 1.0. If I hide the progress bar, as soon as I get 1.0, the user will not see that he will be close to 1.0, he will disappear, perhaps as long as it is 0.7, for example.

My question is, how can I find out when he finished animating the new meaning of progress, so find out when the time is right to hide the idea of ​​progress?

let options = PHImageRequestOptions()
options.networkAccessAllowed = true
options.progressHandler = { (progress: Double, _, _, _) -> Void in
     dispatch_async(dispatch_get_main_queue()) {
         self.barProgressView.setProgress(Float(progress), animated: true)
         //FIXME: Can't do this, otherwise it will hide before animation completes
         self.barProgressView.hidden = (progress <= 0.0 || progress >= 1.0)
    }
}

PHImageManager.defaultManager().requestImageForAsset(photoAsset, targetSize: targetSize, contentMode: .AspectFit, options: options) { (result: UIImage?, info: Dictionary?) -> Void in
    //do something with the image
}
+4
source share

Source: https://habr.com/ru/post/1599777/


All Articles