根据某点获取对应cell

2017-11-15  本文已影响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;
    // 更新底部的数据 
    // ...
}
上一篇 下一篇

猜你喜欢

热点阅读