我的CollectionViewCell
上有一个进度层,用于显示下载进度,我想在下载完成后将其隐藏。但是以某种方式,当它进入假设要隐藏我的视图的if条件时,它不会隐藏。
我尝试将整个内容放入DispatchQueue.main.async
中,但没有成功。我也尝试过放置self.setNeedsDisplay()
或self.layoutIfNeeded()
。我什至尝试了removeFromSuperLayer
,但这些方法都无效,这里的解决方案有点用光了。当下载开始时,我的图层/视图确实出现,当完成时,什么也没发生。
我想念什么,这应该很容易T_T
class DownloadableCollectionViewCell: UICollectionViewCell {
var bgPath: UIBezierPath!
var shapeLayer: CAShapeLayer!
var progressLayer: CAShapeLayer!
var controlButton: UIButton!
var lockIcon: UIImageView!
var frameCenter: CGPoint {
return CGPoint(x: self.frame.width/2, y: self.frame.height/2)
}
private var progress: Float = 0.0 {
didSet(newValue) {
progressLayer.strokeEnd = CGFloat(newValue)
if newValue == 1 {
progressLayer.isHidden = true
controlButton.isHidden = true
lockIcon.isHidden = true
} else {
progressLayer.isHidden = false
controlButton.isHidden = false
}
}
}
public func setProgress(progress: Float) {
self.progress = progress
}
在TableViewCell
中设置进度,CollectionView
持有 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let audioItem = self.listItems[indexPath.row]
let cell = collectionView.cellForItem(at: indexPath) as! AudioCollectionViewCell
if audioItem.isDownloaded {
// Go to next screen
print("Downloaded already!")
} else {
self.downloadAudio(audioPath: audioItem.imageName) { (task) in
task.observe(.progress) { snapshot in
let progress = Float(snapshot.progress!.fileCompletedCount ?? 1) / Float(snapshot.progress!.fileTotalCount ?? 1)
cell.setProgress(progress: progress)
if progress == 1 {
self.listItems[indexPath.row].isDownloaded = true
}
}
}
}
}
var apiPromise = function (url) {
var deferred = $q.defer();
$http.get(url)
.then(function (result) {
deferred.resolve(result.data);
return;
});
return deferred.promise;
};
this.GetExistingStudentTest=function(studentid){
return apiPromise('http://localhost:65196/api/PS/GetStudentTests?studentid=' + studentid + '&testid=2')
};
this.GetExistingStudentTestScores = function (testid) {
return apiPromise('http://localhost:65196/api/PS/GetStudentTestScore?testid=' + testid)
};