Swift UITableViewCell更新中的UIView,无需设置动画
我有一个倒退,我不知道是什么原因造成的 所需:平滑动画 当前:无动画更新 这是导致中断的代码。我不知道为什么Swift UITableViewCell更新中的UIView,无需设置动画,swift,Swift,我有一个倒退,我不知道是什么原因造成的 所需:平滑动画 当前:无动画更新 这是导致中断的代码。我不知道为什么 var pillModel: PillModel? { didSet { guard let pillModel = pillModel else { return } DispatchQueue.main.async { self.movePill(pillModel.side)
var pillModel: PillModel? {
didSet {
guard let pillModel = pillModel else { return }
DispatchQueue.main.async {
self.movePill(pillModel.side)
}
movingPill.backgroundColor = pillModel.movingPillColor
leftLabel.textColor = pillModel.leftLabelColor
rightLabel.textColor = pillModel.rightLabelColor
leftLabel.text = pillModel.leftTekst
rightLabel.text = pillModel.rightTekst
movingPill.layer.applySketchShadow(color: movingPill.backgroundColor!, alpha: 0.7, y: 3)
pillContainer.layoutSubviews()
commonStyle()
}
}
下面是一些相关代码
func movePill( _ sideTouched: Side, _ completion: (() -> ())? = nil) {
constrainPillTo(sideTouched)
pillModel?.side = sideTouched
UIView.animate(withDuration: 0.85, delay: 0, usingSpringWithDamping: 0.65, initialSpringVelocity: 1, options: .transitionCrossDissolve, animations: {
[weak self] in
guard let selfy = self else {return}
selfy.movingPill.backgroundColor = .orange//selfy.pillModel?.movingPillColor
selfy.leftLabel.textColor = .yellow//selfy.pillModel?.leftLabelColor
selfy.rightLabel.textColor = .green//selfy.pillModel?.rightLabelColor
selfy.movingPill.layer.applySketchShadow(color: selfy.movingPill.backgroundColor ?? .socialBlue,
alpha: 0.7, y: 3)
//selfy.pillContainer.layoutSubviews()
}) { _ in
completion?()
}
}
结果是我创造了一个循环。当我将代码从pillModel属性的didSet方法移到它自己的函数中时,问题完全解决了 @Sh_Khan我应该如何将更改显示为文本?点击时Cellforrow会被调用吗?看起来你现在正在创建一个新的细胞,而不是抓取一个持久的细胞?@Joe,这是一个很好的想法,但是我不给cellforrowat打电话。。。