UICollectionView incorrectly hides cells during layout transition

There are a few UICollectionView error UICollectionView that hide cells, but I don't think it was covered. Most of the other issues are usually related to the UICollectionViewFlowLayout and the insert sections, whereas I saw this problem when switching between fully custom layouts.


When performing an interactive layout UICollectionView , the UICollectionView seems to hide cells that should not be hidden:

enter image description here

(Note that cells 40 and 45 in the lower left corner disappear during the transition)

This seems to happen in a certain place: whenever the cell layout attributes (returned from the transition layout layoutAttributesForElementsInRect: have a frame with minX less than the one passed to rect minX AND a maxY more than rect MAXY. In code:

 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSArray *layoutAttributes = [super layoutAttributesForElementsInRect:rect]; for (UICollectionViewLayoutAttributes *attr in layoutAttributes) { if (CGRectGetMinX(attr.frame) < CGRectGetMinX(rect) && CGRectGetMaxY(attr.frame) > CGRectGetMaxY(rect)) { NSLog("Element at index path %@ will disappear unexpectedly", attr.indexPath); } } return layoutAttributes; } 

The transition layout returns the correct layout attributes, showing that the center of the cell is gradually moving off-frame. However, once it passes the point mentioned above, the collection view seems to decide that it is no longer visible (it!) And sets the hidden cell property to yes, ignoring it until its frame moves further within the rect .

I put together a project that demonstrates this problem (the animation above refers to this sample in action). It uses two simple stream layouts for simplicity, but I first noticed this when working with the transition between custom subclasses of UICollectionViewLayout . Most of the code is just managing the interactive transition using a gesture recognizer, and I'm pretty sure there is nothing wonderful there.

The problem does not occur when using simple animated layout transitions ( setCollectionViewLayout:animated: ... try to run a sample project with slow animation and click on a cell - all cells expect as expected.

This seems like a mistake in implementing UICollectionView for me, but I would really appreciate it if anyone knows of an efficient workaround.


Update:

I published a bug report with Apple and at the same time opened the Technical Support Incident to find out if a workaround could be found. I will add an answer if I learn anything useful from the engineers.

Update:

Apple DTS responded to confirm that this is a bug and that there is no workaround. For my case, I ended up just causing the disappearing cells to not reach the magic threshold, because of which they disappeared.

+6
source share

Source: https://habr.com/ru/post/969550/


All Articles