如何在重用发生时重绘不可见的UICollectionViewCell?
我想到的一种方法是使用Layout Cell prepareForReuse函数中的代码,但是它的工作方式非理想,因为它会导致需要更多的重新绘制.
背景:需要drawRect在方向更改后触发单元格,这些方向更改当前不可见,但弹出使用并且尚未重绘,所以到目前为止我只能看到这prepareForReuse是合适的.问题是我正在重新绘制所有"重用"单元格,而我真的只想重绘最初弹出的那些在设备的前一个方向位置创建的单元格.
附加信息:所以目前我这样做:
在ViewController中:
override func viewWillLayoutSubviews() {
// Clear cached layout attributes (to ensure new positions are calculated)
(self.cal.collectionViewLayout as! GCCalendarLayout).resetCache()
self.cal.collectionViewLayout.invalidateLayout()
// Trigger cells to redraw themselves (to get new widths etc)
for cell in self.cal?.visibleCells() as! [GCCalendarCell] {
cell.setNeedsDisplay()
}
// Not sure how to "setNeedsDisplay" on non visible cells here?
}
Run Code Online (Sandbox Code Playgroud)
在Layout Cell类中:
override func prepareForReuse() {
super.prepareForReuse()
// Ensure "drawRect" is called (only way I could see to …Run Code Online (Sandbox Code Playgroud) ios uicollectionview uicollectionviewcell swift prepareforreuse