【发布时间】:2014-02-19 08:52:20
【问题描述】:
我使用以下代码在水平方向上对collection view 进行了分页。
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.pagingEnabled = YES;
self.collectionView.directionalLockEnabled = YES;
self.collectionView.bounces = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.delegate = self;
[self setup];
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = floor(self.collectionView.contentSize.width / self.collectionView.frame.size.width) + 1;
}
我使用pageControl 表示我有多少页和当前页。
我使用类似于以下链接的方法来确定当前页面。
iOS6 UICollectionView and UIPageControl - How to get visible cell?
UICollectionView: current index path for page control
如下。
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSInteger currentPage = self.collectionView.contentOffset.x / self.collectionView.frame.size.width;
self.pageControl.currentPage = currentPage;
}
但是,它不起作用。当我将collection view 滑动到下一页时,pageControl 仍然指向第一页。它不会改变它的值。
我打印出self.collectionView.contentOffset.x 值,它总是在框架内(这是第一页,即使我已经滑动到下一页),它永远不会转到下一页。
我是不是做错了什么?
【问题讨论】:
标签: ios uicollectionview