UICollectionView insert cells above maintaining position (like Messages.app)

后端 未结 20 2039
渐次进展
渐次进展 2020-12-02 07:23

By default Collection View maintains content offset while inserting cells. On the other hand I\'d like to insert cells above the currently displaying ones so that they appea

20条回答
  •  渐次进展
    2020-12-02 08:08

    This is the technique I use. I've found others cause strange side effects such as screen flicker:

        CGFloat bottomOffset = self.collectionView.contentSize.height - self.collectionView.contentOffset.y;
    
        [CATransaction begin];
        [CATransaction setDisableActions:YES];
    
        [self.collectionView performBatchUpdates:^{
            [self.collectionView insertItemsAtIndexPaths:indexPaths];
        } completion:^(BOOL finished) {
            self.collectionView.contentOffset = CGPointMake(0, self.collectionView.contentSize.height - bottomOffset);
        }];
    
        [CATransaction commit];
    

提交回复
热议问题