UIGestureRecognizerDelegate 先遵从协议
longPressGr =
=
=
=
2.我们在longpressToDo里面添加方法-(
)longPressToDo:(UILongPressGestureRecognizer *
(gestureRecognizer.state !=
=
*indexPath =
(indexPath ==
UICollectionViewCell* cell =
这里我们为tableview添加长按手势
UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]
longPressGr.minimumPressDuration = 0.5f
longPressGr.numberOfTouchesRequired = 1
[_tableView addGestureRecognizer:longPressGr]
[longPressGr release]
这时我们会发现每次按住tableView并且松开的时候, longPressAction: 这个方法会执行2次
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan) {
CGPoint point = [longPress locationInView:_tableView]
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:point]// 可以获取我们在哪个cell上长按
if (indexPath != nil) {
NSLog(@"%ld", indexPath.row)
}
}
}
第一步给cell添加长按方法
第二步触发的方法
-(void)longclick:(UIGestureRecognizer *)gar{
switch (gar.state) {
}
}
//第三步:设定单位格可移动
-(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath{
}
//第四步:改变数据源顺序
-(void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
// FLmodel *model = [_dataSource objectAtIndex:sourceIndexPath.item]
MenuInfoModel *model =[self.dataSource objectAtIndex:sourceIndexPath.item]
[_dataSource removeObject:model]
[_dataSource insertObject:model atIndex:destinationIndexPath.item]
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)