美文网首页
CollectionView 分区内item的移动

CollectionView 分区内item的移动

作者: Poison_19ce | 来源:发表于2017-06-29 10:23 被阅读0次

首先我们要移动item 会用到几个方法

1、加手势 longPress 

2、手势中的状态

UIGestureRecognizerStateBegan //手势开始

UIGestureRecognizerStateChanged //手势改变

UIGestureRecognizerStateEnded://手势结束

3、在手势结束的时候 会回调 collectionView的 

-(void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

4、还有三个核心的方法

beginInteractiveMovementForItemAtIndexPath:  //在手势状态开始的时候调用

updateInteractiveMovementTargetPosition: //在手势改变状态时调用

endInteractiveMovement //在手势结束时调用

5、NSIndexPath *index = [collectionView indexPathForItemAtPoint:point];//此方法可以获得手势所选中点对应的item下标

6、最后记得 跨分区移动 要在第3点的方法中对二维数组中的内容进行remove以及insertObject:AtIndex:

相关文章

网友评论

      本文标题:CollectionView 分区内item的移动

      本文链接:https://www.haomeiwen.com/subject/zecmcxtx.html