iOS中删除单元格时UICollectionView的动画时间 [英] Animation time of UICollectionView on deletion of cell in iOS

查看:40
本文介绍了iOS中删除单元格时UICollectionView的动画时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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


}

这篇关于iOS中删除单元格时UICollectionView的动画时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆