- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
在上述委托方法中,执行以下操作:
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];
}