[英]Animation time of UICollectionView on deletion of cell in iOS
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 . 我正在使用集合视图,我第一次需要删除click.which正常工作的集合视图的单元格。但我正在努力与UIcollectionview的动画时间。它总是一样的。我怎么能增加删除单元格时减少动画时间。我也将该代码放在uianimation块中,但它不起作用。 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];
}
Use collection view apple link hope will help. 使用集合视图苹果链接希望会有所帮助。 https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/Introduction/Introduction.html
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/Introduction/Introduction.html
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.