4

我第一次使用集合视图我需要在单击时删除集合视图的单元格。这对我来说工作正常。但我正在努力处理 UIcollectionview 的动画时间。它总是一样的。我怎样才能增加或减少删除单元格的动画时间。我也将该代码放在 uianimation 块中,但它不起作用。这是我的删除代码,任何建议将不胜感激,谢谢。

  [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

1 回答 1

6
- (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];


}
于 2013-09-20T06:55:40.197 回答