且构网

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

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

更新时间:2023-02-16 15:29:37

我也遇到过类似的问题.这很可能是因为重用的单元格不会自己重绘.在您的自定义单元格的 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;

在初始化期间.