Large UICollectionViewCell stopped being displayed when scrolling

前端 未结 4 623
夕颜
夕颜 2020-12-25 14:21

The same behavior of UICollectionView as described here has been led to this question. Even though I decided to post my own one, because I did further investiga

4条回答
  •  独厮守ぢ
    2020-12-25 14:39

    My solution is basically the same as Jonathan's but in a category, so you don't have to use your own subclass.

    @implementation UICollectionView (MTDFixDisappearingCellBug)
    
    + (void)load {
        NSError *error = nil;
        NSString *visibleBoundsSelector = [NSString stringWithFormat:@"%@isib%@unds", @"_v",@"leBo"];
    
        if (![[self class] swizzleMethod:NSSelectorFromString(visibleBoundsSelector) withMethod:@selector(mtd_visibleBounds) error:&error]) {
            FKLogErrorVariables(error);
        }
    }
    
    - (CGRect)mtd_visibleBounds {
        CGRect bounds = [self mtd_visibleBounds]; // swizzled, no infinite loop
        MTDDiscussCollectionViewLayout *layout = [MTDDiscussCollectionViewLayout castedObjectOrNil:self.collectionViewLayout];
    
        // Don`t ask me why, but there's a visual glitch when the collection view is scrolled to the top and the max height is too big,
        // this fixes it
        if (bounds.origin.y <= 0.f) {
            return bounds;
        }
    
        bounds.size.height = MAX(bounds.size.height, layout.maxColumnHeight);
    
        return bounds;
    }
    
    @end
    

提交回复
热议问题