ios - UICollectionView: Adding item at a specified Index and scroll to this item -
i have created vertical scrolling custom layout uicollectionview
. items added collection through classic pull add , shown in alphabetical order. if add item starts z letter placed @ end of collection want collection scroll automatically show last cell.
currently i'm using code:
[self.collectionview performbatchupdates:^{ // update datasource [self updatetasks]; // insert new item collection [self.collectionview insertitemsatindexpaths:@[[nsindexpath indexpathforitem:[self.tasks indexofobject:task] insection:0]]]; } completion:^(bool finished) { // reload data , scroll [self.collectionview reloaddata]; [self.collectionview scrolltoitematindexpath:@[[nsindexpath indexpathforitem:[self.tasks indexofobject:task] insection:0] atscrollposition:uicollectionviewscrollpositiontop animated:yes]; }];
it works... can see use performbatchupdates
add item. uicollectionview
automatically animated present new cell , shift other cells. animation not shown if uicollectionview
has scroll. because scrollview animating too...
in opinion best way insert item in collection view , scroll new item? i'm having hard time trying obtain beautiful , smooth animation show user new item in fashion way.
edit-------
if remove call reloaddata
method scrolltoitematindexpath
doesn't work... uicollectionview doesn't scroll @ all.
you not have reload data if using performbatchupdate. remove [self.collectionview reloaddata];
completion block , should works.
Comments
Post a Comment