UICollectionView:页面控制的当前索引路径 [英] UICollectionView: current index path for page control

查看:540
本文介绍了UICollectionView:页面控制的当前索引路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有流布局的UICollectionView来显示单元格列表,我还有一个页面控件来指示当前页面,但似乎无法获取当前索引路径,我知道我可以看到单元格:

I'm using a UICollectionView with a flow layout to show a list of cells, I also have a page control to indicate current page, but there seems to be no way to get current index path, I know I can get visible cells:

UICollectionView当前可见单元格索引

然而,如果我将每个单元格占据屏幕的整个宽度,可以有多个可见单元格,如果我将其滚动到两半两个单元格,然后它们都是可见的,那么有没有办法只获得一个当前可见单元格的索引?

however there can be more than one visible cells, even if each of my cells occupies full width of the screen, if I scroll it to have two halves of two cells, then they are both visible, so is there a way to get only one current visible cell's index?

谢谢

推荐答案

您可以通过监视scrollViewDidScroll委托中的contentOffset获取当前索引

You can get the current index by monitoring contentOffset in scrollViewDidScroll delegate

它将是这样的

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger currentIndex = self.collectionView.contentOffset.x / self.collectionView.frame.size.width;

}

这篇关于UICollectionView:页面控制的当前索引路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆