问题
I'm performing a request to get an image asset given a PHAsset
, and I'm using UIProgressView
to indicate the progress using the progressHandler
PHImageRequestOptions
allows me to provide. When that handler is called, it provides me with progress
so I set the progress on the progress view but I also animate to that new progress via setProgress:animated:
. I now need to figure out how to hide the progress view once progress has reached 1.0, but not until it has finished animating to 1.0.
For example, it might begin to download the asset, call the progress callback with 0.2, then the next callback might be 1.0. If I hide the progress bar as soon as I get 1.0, the user won't see it animate to 1.0, it will disappear perhaps while it's at 0.7 for example.
My question is, how can I know when it has finished animating to the new progress value, therefore know when it's the right time to hide the progress view?
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
}
来源:https://stackoverflow.com/questions/31643440/hide-uiprogressview-after-fetch-for-phasset-is-completed-and-progress-finished-a