有没有办法知道哪个集合视图单元格在特定点? [英] Is there any way to know which collection view cell is at a specific point?

查看:27
本文介绍了有没有办法知道哪个集合视图单元格在特定点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CGPoint,我想知道我的集合视图中的哪个单元格当前包含该点.有什么简单的方法可以做到这一点还是我必须编写自己的方法?

I have a CGPoint and I would like to know which cell from my collection view currently contains that point. Is there any simple way to do this or do I have to write my own method?

推荐答案

UICollectionView我用的不多,但是有一个方法看起来很完美:

I haven't used UICollectionViews much, but there's a method that seems perfect:

- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point;

传递给方法的点必须在集合视图的坐标系内.你可以这样做:

The point you pass to the method has to be within the coordinate system of the collection view. You can do:

CGPoint convertedPoint = [collectionView convertPoint:point fromView:viewThatYouGotThePointFrom];

获得正确的观点,如果您得到的观点最初不是来自集合视图.

to get the correct point, if the point you got isn't from the collection view originally.

这篇关于有没有办法知道哪个集合视图单元格在特定点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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