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

查看:203
本文介绍了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天全站免登陆