ios - UICollectionView:获取屏幕位置的单元格

标签 ios objective-c uicollectionview

我有一个使用 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/

相关文章:

ios - 将 UIImageView 添加到 rootViewController

objective-c - 在 iPhone 上使用 NSRegularExpression 提取 URL

swift - 更新 CollectionView 中的数据模型以过滤单元格

ios - 如何避免在表格 View 中突出显示两个单元格?

ios - 获取错误 "Cannot load module ' MapKit' 作为 'MapKit'“

objective-c - UIButton 触发选择器不一致

ios - 两 ListView ?

ios - 使用 Storyboard从 App Delegate 呈现模态视图 Controller

iphone - 这个平移手势识别器 Action 有什么问题?

ios - 如何只能在UICollectionView中的Indexpath.section之间滚动排除indexpath.row