IOS CollectionView 拖拽移动
来源:互联网 发布:美分知乎 编辑:程序博客网 时间:2024/06/03 22:46
collection 增加长按手势
//添加长按的手势 UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; [collectionView addGestureRecognizer:longPress];
- (void)longPress:(UIGestureRecognizer *)longPress { //获取点击在collectionView的坐标 CGPoint point=[longPress locationInView:self.collectionView]; //从长按开始 if (longPress.state == UIGestureRecognizerStateBegan) { NSIndexPath *indexPath=[self.collectionView indexPathForItemAtPoint:point]; [self.collectionView beginInteractiveMovementForItemAtIndexPath:indexPath]; //长按手势状态改变 } else if(longPress.state==UIGestureRecognizerStateChanged) { [self.collectionView updateInteractiveMovementTargetPosition:point]; //长按手势结束 } else if (longPress.state==UIGestureRecognizerStateEnded) { [self.collectionView endInteractiveMovement]; //其他情况 } else { [self.collectionView cancelInteractiveMovement]; }}- (NSIndexPath *)collectionView:(UICollectionView *)collectionView targetIndexPathForMoveFromItemAtIndexPath:(NSIndexPath *)originalIndexPath toProposedIndexPath:(NSIndexPath *)proposedIndexPath { /* 两个indexpath参数, 分别代表源位置, 和将要移动的目的位置*/ //-1 是为了不让最后一个可以交换位置 if (proposedIndexPath.item == (_dataArrays.count - 1)) { //初始位置 return originalIndexPath; } else { //-1 是为了不让最后一个可以交换位置 if (originalIndexPath.item == (_dataArrays.count - 1)) { return originalIndexPath; }// 移动后的位置 return proposedIndexPath; }}-(void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ //记录要移动的数据 id object= self.dataArrays[sourceIndexPath.item]; //删除要移动的数据 [self.dataArrays removeObjectAtIndex:sourceIndexPath.item]; //添加新的数据到指定的位置 [self.dataArrays insertObject:object atIndex:destinationIndexPath.item];}
0 0
- IOS CollectionView 拖拽移动
- iOS 开发中移动collectionView的item
- iOS CollectionView
- iOS---collectionView
- ios collectionView
- iOS collectionView使用
- iOS collectionview小结
- iOS开发中的collectionView
- iOS CollectionView简单使用
- collectionView的使用iOS
- iOS collectionView的使用
- iOS-CollectionView 基础
- iOS-CollectionView流水布局
- IOS CollectionView 线性布局
- iOS--集合视图CollectionView
- iOS 单元格CollectionView简介
- IOS开发之CollectionView
- iOS collectionView返回顶部
- 深入理解 JavaScript 错误和堆栈追踪
- Andriod中自定义Dialog样式的Activity点击空白处隐藏软件盘(Dialog不消失)
- USB设备驱动一
- android 使用asynctask结合fragment更新UI(另附线程池管理示例)
- YOLOv2论文理解
- IOS CollectionView 拖拽移动
- Activity 的启动模式
- Linux内核系统调用的添加
- GRAN论文翻译
- 【Linux】File 结构体,和 fd 的关系
- 大数据-Hadoop学习笔记09
- 归并排序
- spring中bean的配置
- 学习笔记之SharedPreference问题解答