我有一个使用 JSON 填充的 UICollectionView。这是带有电影海报的 coverflow 风格布局。
我想知道是否有一种方法可以让我在屏幕上的某个点显示单元格的标题属性,以便当我水平滚动时,显示最中心可见单元格的标题。
我尝试过使用 indexPathForItemAtPoint,但该点似乎随 Collection View 滚动,始终显示相同的索引。
编辑: 添加代码:
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);
非常感谢您的帮助, 洛根
最佳答案
尝试在执行转换点时交换项目,这样您就可以从父 View 转到 Collection View :
NSIndexPath *path = [self.boxes indexPathForItemAtPoint:[[self.boxes superview] convertPoint:CGPointMake(100.0, 100.0) toView:self.boxes]];
关于ios - UICollectionView:获取屏幕位置的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18728488/