5

我正在执行一个请求以获取给定的图像资产PHAsset,并且我正在使用允许我提供UIProgressView的来指示进度。progressHandler PHImageRequestOptions当调用该处理程序时,它会为我提供,progress因此我在进度视图上设置进度,但我也通过setProgress:animated:. 我现在需要弄清楚如何在进度达到 1.0 后隐藏进度视图,但要等到它完成动画到 1.0 后才可以。

例如,它可能开始下载资产,使用 0.2 调用进度回调,然后下一个回调可能是 1.0。如果我一获得 1.0 就隐藏进度条,用户不会看到它动画到 1.0,它可能会在例如 0.7 时消失。

我的问题是,我怎么知道它何时完成了新进度值的动画,因此知道何时是隐藏进度视图的正确时间?

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

0 回答 0