且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UICollectionView在滚动后显示错误的单元格-出队问题?

更新时间:2023-02-16 15:03:25

我遇到了相似的问题.这很可能是因为重用的单元格不会重绘自身.在自定义单元格的 content 类(您的PDF视图)中,如果框架更新,则触发重绘:

I've had similare issues. This is most likely because the reused cells do not redraw themselves. In your custom cell's content class (your PDF view), trigger redrawing if the frame is updated:

-(void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    [self setNeedsDisplay]; // force drawRect:
}

这对我有用.另外,如果您的像元大小可能会改变,请设置自动调整大小蒙版,以使其充满空间

This worked for me. In addition, if your cell size may change, set the autoresizing mask so that it fills space with

self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

初始化期间.