UICollectionView 在单元格上拖动手指以选择它们 [英] UICollectionView drag finger over cells to select them

查看:7
本文介绍了UICollectionView 在单元格上拖动手指以选择它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 UICollectionView,是否可以通过将手指拖动到其中几个单元格上来选择多个单元格?例如,如果您将手指拖动到一行 6 上,然后向下移动到下一行,它将选择所有这些.

Using UICollectionView, is it possible to select multiple cells by dragging your finger over a few of them? E.g., if you drag your finger over a row of 6, and down into the next row, it would select all of them.

尝试了一些简单的东西:

Tried something simple:

UISwipeGestureRecognizer *swipeGuesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self.collectionView addGestureRecognizer:swipeGuesture];

但这似乎只调用了第一个被触摸的单元格上的方法.

But that seemed to only call the method on the first cell that was touched.

有什么想法吗?

推荐答案

你可以使用 UIPanGestureRecognizer.并根据平移事件的位置,跟踪通过了哪些单元格.当手势结束时,您将拥有一组选定的单元格.

You could use UIPanGestureRecognizer. And based on the location of the pan events, tracking what cells are passed through. When the gesture ends, you would have an array of selected cells.

确保 cancelsTouchesInView 设置为 NO.您需要使用 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:gestureRecognizerShouldBegin 设置委托,以确保 CollectionView 仍然可以滚动

Make sure that cancelsTouchesInView is set to NO. You'll need to set the delegate with gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and gestureRecognizerShouldBegin implemented to make sure the CollectionView can still scroll

这篇关于UICollectionView 在单元格上拖动手指以选择它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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