关于scrollerView+tableView+collectionView的小知识点

1、经常有表滑动,根据当前滑动的contentoffset来决定界面的UI显示,不要傻乎乎的再去计算位移量等操作了,oc有提供方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
   
      //获取collectionView中心的cell
      NSIndexPath *centerindexPath = [self.collectionView indexPathForItemAtPoint:CGPointMake(scrollView.contentOffset.x + self.collectionView.width / 2.0, 0)];

      //系统方法返回处于tableView某坐标处的cell的indexPath
      NSIndexPath * indexPath = [collectionView indexPathForRowAtPoint:scrollView.contentOffset];
      NSLog(@"滑到了第 %ld 组 %ld个",indexPath.section, indexPath.row);
}


猜你喜欢

转载自blog.csdn.net/weixin_41953322/article/details/80803556