【发布时间】:2020-01-24 12:53:44
【问题描述】:
我想创建一个属性包装器,它使我的UICollectionViewLayout 的布局无效。
因此我创建了这个属性包装器
@propertyWrapper
class LayoutInvalidating {
private let layout: UICollectionViewLayout
init(layout: UICollectionViewLayout) {
self.layout = layout
self.wrappedValue = layout
}
var wrappedValue: UICollectionViewLayout {
didSet {
self.layout.invalidateLayout()
}
}
}
那我想如下使用它
final class VehicleControlsCollectionViewLayout: UICollectionViewLayout {
@LayoutInvalidating(layout: self) // self is not alive
public var itemSize: CGSize = .init(width: 70, height: 70)
}
每次设置属性时,我都想致电self.invalidateLayout()。有什么想法可以在 self 存在时访问它吗?
【问题讨论】: