美文网首页
根据某点获取对应cell

根据某点获取对应cell

作者: 思念那年慕云 | 来源:发表于2017-11-15 10:39 被阅读17次

➤ indexPathForItemAtPoint:根据某点获取indexPath

注意:这个方法传入的参数point是以scrollView的contentView为坐标系的坐标
#举例:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    // 将collectionView在控制器view的中心点转化成collectionView上的坐标
    CGPoint pInView = [self.view convertPoint:self.collectionView.center toView:self.collectionView];
    // 获取这一点的indexPath
    NSIndexPath *indexPathNow = [self.collectionView indexPathForItemAtPoint:pInView];
    // 赋值给记录当前坐标的变量
    self.currentIndexPath = indexPathNow;
    // 更新底部的数据 
    // ...
}

相关文章

网友评论

      本文标题:根据某点获取对应cell

      本文链接:https://www.haomeiwen.com/subject/twxjmxtx.html