【发布时间】:2016-08-09 19:38:48
【问题描述】:
我想在 CollectionViewCell 中添加一个 progressView。 ProgressView 应该是动画的,并在 10 秒内运行 von 1 到 0 的进度。
所以现在对每个进度视图都使用“viewWithTag”,并更新我的进度:
UIView.animateWithDuration(3, animations: { () -> Void in
progressView.setProgress(1.0, animated: true)
})
但是,我想它必须容易得多。当生病重新加载单元格时,我想再次为进度设置动画。那么直接将该功能包含在我的单元格中是否应该更容易?
喜欢:
override func prepareForReuse() {
super.prepareForReuse()
print("prepareForReuse")
UIView.animateWithDuration(3, animations: { () -> Void in
progressView.setProgress(1.0, animated: true)
})
}
但这不起作用,滚动时也应该是一个问题。有没有办法让单元格中的 progressView 动画精确 10 秒,并且(当你滚动时)progressView 仍然没有从头开始?
好的,当我更新我的单元格时,我现在开始我的动画:
func updateCell() {
photos[2].comment = "dsadhjsa hdjksahdjsahfk jhasfjklha fjkhdjsk fhjksdf hjskdfh jkdshfjksdh fdhsjkfhdsjkf dsadsad dsad sad " // test Test
let h: Int = random() % 100;
photos[2].height = 120 + CGFloat(h) // set custom height for test
let path = NSIndexPath(forItem: 2, inSection: 0)
self.collectionViewLayout.invalidateLayout()
collectionView?.reloadItemsAtIndexPaths([path])
if let progressView = view.viewWithTag(2) as? UIProgressView {
progressView.setProgress(0, animated: false)
UIView.animateWithDuration(4, animations: { () -> Void in
progressView.layoutIfNeeded()
progressView.setProgress(1, animated: true)
})
}
}
这是有效的,但是(当然)当我向下滚动时,我的单元格会丢失动画。我想这将是存储当前进度值的更好方法,如果单元格再次可见,我会再次加载它吗?
或者还有其他可能性吗?
【问题讨论】:
-
在动画块中添加 0.5 秒的延迟。
-
当单元格被重用时,这对我有什么帮助(所以动画从头开始?)
标签: ios swift uicollectionview