0
class SceneCell: UICollectionViewCell {
override var isSelected: Bool {
didSet {
setSelected(bool: isSelected)
}
}
override var isHighlighted: Bool {
didSet {
setHighlighted(bool: isHighlighted)
}
}
@IBOutlet weak var thumbnailImageView: UIImageView!
override func draw(_ rect: CGRect) {
super.draw(rect)
self.backgroundColor = .clear
self.thumbnailImageView.layer.borderColor = UIColor.green.cgColor
self.thumbnailImageView.layer.masksToBounds = true
self.thumbnailImageView.clipsToBounds = true
self.thumbnailImageView.layer.cornerRadius = 8
}
func update(with scene: Scene) {
}
private func setHighlighted(bool: Bool) {
if bool {
self.alpha = 0.5
} else {
self.alpha = 1.0
}
}
private func setSelected(bool: Bool) {
if bool {
self.thumbnailImageView.layer.borderWidth = 2.5
} else {
self.thumbnailImageView.layer.borderWidth = 0
}
}
}
在我的代码中,当被选中时,我将图像视图的图层边框宽度更改为2.5设置为true。使用属性观察器更改集合视图单元格很不好吗?
当我选择一个单元格并滚动集合视图时,我认为当重用该选定单元格时单元格保持选中状态,但重用单元格更改为未选中状态。其次,当我回到选定的单元格并重新使用未选中的单元格时,我认为它处于未选定状态。但是单元格是自动设置的。
剂量收集视图自动管理这些?
但我的代码完美地工作。 – Sohn
与重复使用问题完美结合使用?我想它在没有滚动的情况下工作完美,是吗? –
它没有重用问题。我的问题是为什么这个代码运行良好。 – Sohn