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

后端 未结 20 2037
渐次进展
渐次进展 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:27

    if ([newMessages count] > 0)
    {
        [self.collectionView reloadData];
    
        if (hadMessages)
            [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:[newMessages count] inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
    }
    

    This seems to be working so far. Reload the collection, scroll the previously first message to the top without animation.

提交回复
热议问题