UICollectionView animation time when deleting a cell in iOS

I am using the collection view for the first time when I need to remove the collection view cell on click.which works correctly for me. But I am struggling with the animation time of the UIcollectionview. It is always the same. I can increase or decrease the animation time when deleting a cell. I also put this code in a uianimation block, but it does not work. Here is my removal code, any advice would be highly appreciated.

[self.collectionView performBatchUpdates:^{ NSArray* itemPaths = [self.collectionView indexPathsForSelectedItems]; // Delete the items from the data source. [self deleteItemsFromDataSourceAtIndexPaths:itemPaths]; // Now delete the items from the collection view. [self.collectionView deleteItemsAtIndexPaths:tempArray } completion:nil]; 
+4
source share
2 answers
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

in the delegate method above, do the following:

 NSIndexPath *lIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:lIndexPath]; //Perform flip animation //_AnimationDuration defined in Constant.h CGContextRef context = UIGraphicsGetCurrentContext(); context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationDuration:_AnimationDuration]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell cache:YES]; [UIView commitAnimations]; //Implementation of GCD to delete a flip item double delay = _AnimationDuration/2; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ //code to be executed on the main queue after delay [self deleteContent:indexPath]; }); -(void) deleteContent:(NSIndexPath *)_indexPath{ //Remove items from array on delete [itemArr removeObjectAtIndex:_indexPath.row]; //Reload the items of UICollectionView performBatchUpdates Block [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:@[_indexPath]]; } completion:nil]; } 
+6
source

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


All Articles