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

查看:31
本文介绍了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天全站免登陆