我正在使用 CKOperation 将记录数组保存在云套件中,如下所示并使用进度 View 显示进度。
let saveOperation = CKModifyRecordsOperation(recordsToSave: ckRecord, recordIDsToDelete: nil)
saveOperation.perRecordProgressBlock = {
record, progress in
if progress >= 1 {
self.completedRecord.addObject(record)
let totalSavedRecord = Double(self.completedRecord.count)
let totalProgress = totalSavedRecord / self.totalStudent
let percentageProgress = Float(totalProgress * 100)
progressView.setProgress(percentageProgress, animated: true)
println(progress)
println(progressView.progress)
println(percentageProgress)
}
}
我想在进度 View 达到 100% 且动画完成时隐藏进度 View 。
目前,我很快就达到了百分比进度 100.0,但进度 View 动画发生时有一些延迟。如果我在百分比进度达到 100.0 时隐藏,那么我将永远不会看到任何动画。
进度值始终为 1.0。
progressView.progress 的值始终为 1.0。
我想再次显示从 0% 到 100% 的完整动画,然后隐藏进度 View 。
最佳答案
CloudKit 回调 block 在后台线程上执行。当您更新 UI 时,您应该在主线程上执行此操作。否则你可能会看到像这样奇怪的延迟。尝试将代码包装在如下所示的 block 中:
NSOperationQueue.mainQueue().addOperationWithBlock {
progressView.setProgress(percentageProgress, animated: true)
}
关于ios - 动画完成时隐藏 UIProgressView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30766311/