【问题标题】:Animation time of UICollectionView on deletion of cell in iOSiOS中删除单元格时UICollectionView的动画时间
【发布时间】:2013-05-24 19:55:16
【问题描述】:

我第一次使用集合视图,我需要在单击时删除集合视图的单元格。这对我来说工作正常。但我在 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];  

【问题讨论】:

    标签: iphone ios objective-c uicollectionview


    【解决方案1】:
    - (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];
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多