Reputation: 1558
I am using collection view for the very first time i need to delete the cell of the collection view on click.which is working properly for me.But i am struggling with the animation time of UIcollectionview .It is always same .How can i increase or decrease the animation time on deletion of the cell.I am also putting that code in uianimation block but it is not working . Here is my code on deletion,any advise would be highly appreciated thanks.
[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];
Upvotes: 4
Views: 4999
Reputation: 852
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
in the above delegate method, 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];
}
Upvotes: 6