我有一个收集视图单元格,该单元格内有一个按钮。当我点击单元格(使用.touchUpInside
)时,我看不到应该发生的布局更改。
这是被调用的action方法。我知道它被适当地调用了,因为我得到了日志button tapped touch down
。
我的收藏夹视图使用合成布局和UIDiffableDataSource
。
@objc func buttonTapped() {
print("button tapped touch down")
self.button.isSpinning = true
}
上述操作会在视图中设置属性isSpinning
,该属性应触发活动指示器的动画和背景颜色变化。 SmallCellButton
是一个类,它是一个UIView,其顶部带有透明按钮。在此集合视图方案以外的其他情况下使用时,它完全可以正常工作。
class SmallCellButton : UIView {
...
var isSpinning : Bool = false {
didSet {
if isSpinning {
print("should be spinning")
self.label.isHidden = true
self.activityIndicator.startAnimating()
self.activityIndicator.alpha = 1
self.layer.borderColor = UIColor.white.withAlphaComponent(0.2).cgColor
self.layer.backgroundColor = UIColor.black.cgColor
} else {
print("should stop spinning")
self.label.isHidden = false
self.activityIndicator.alpha = 0
self.activityIndicator.stopAnimating()
self.layer.borderColor = UIColor.clear.cgColor
self.layer.backgroundColor = UIColor.white.withAlphaComponent(0.2).cgColor
}
}
}
}
我得到了"should be spinning"
的日志,但是在.touchUpInside
事件之后我从未看到布局更改。我可以使用调试器逐步浏览所有布局代码,但是看不到视觉变化。
如果将布局代码从isSpinning
移至覆盖的isHighlighted
属性,则布局代码将执行并以可视方式显示。如果我将其移至覆盖的isSelected
属性,则它不会直观显示,但会执行。