[英]UICollectionView: Get cell at screen position
I have a UICollectionView that I have populated using JSON. 我有一个使用JSON填充的UICollectionView。 It is a coverflow style layout with movie posters.
这是带有电影海报的Coverflow样式布局。
I was wondering if there was a way for me to display the title property of a cell at a certain point on the screen so that when i scroll horizontally, the title of the very center visible cell is displayed. 我想知道是否有一种方法可以在屏幕上的某个点显示单元格的title属性,以便当我水平滚动时,显示非常中心可见的单元格的标题。
I have tried using indexPathForItemAtPoint, but the point seems to scroll with the collection view, always displaying the same index. 我尝试使用indexPathForItemAtPoint,但是该点似乎随着集合视图滚动,始终显示相同的索引。
EDIT: adding code: 编辑:添加代码:
UIView *test = [[UIView alloc] initWithFrame:CGRectMake(10, 30, self.view.frame.size.width+180, 390)];
test.backgroundColor = [UIColor clearColor];
superView.backgroundColor = [UIColor blackColor];
PerspectiveFlowLayout *layout = [[PerspectiveFlowLayout alloc]init];
self.boxes.bounces = NO;
BoxView *boxes = [[BoxView alloc] initWithFrame:test.frame collectionViewLayout:layout];
[test addSubview:boxes];
[superView addSubview: test];
NSIndexPath *path = [self.boxes indexPathForItemAtPoint:[self.boxes convertPoint:CGPointMake(100.0, 100.0) toView:[self.boxes superview]]];
Cell *atpoint = [self.boxes cellForItemAtIndexPath:path];
NSLog(@"%@", atpoint.model.name);
Thank you so much for your help, Logan 洛根,非常感谢您的帮助
进行转换点时,请尝试将项目四舍五入交换,因此您将从超级视图转到集合视图:
NSIndexPath *path = [self.boxes indexPathForItemAtPoint:[[self.boxes superview] convertPoint:CGPointMake(100.0, 100.0) toView:self.boxes]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.