我进行了回归分析,但我不知道是什么原因引起的。
这是导致中断的代码。我不知道为什么
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?()
}
}
答案 0 :(得分:-1)
事实证明,我创建了一个循环。当我将代码从pillModel
属性的didSet
方法移到其自己的函数中时,此问题已完全解决。