【发布时间】:2014-02-27 16:33:56
【问题描述】:
我有一个垂直的UICollectionView,每个单元格都占据了整个self.view.frame,我可以轻松地向上滑动以翻页到下一个单元格,但我想通过按下按钮来做同样的事情。
我尝试过使用:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
还有:
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
它们可以工作,但它们会暂时“白化”currentCell 以呈现下一个Cell,而在过渡期间滑动会显示两个单元格。
理想情况下我想使用:
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
但我不知道如何访问 nextCell 的indexPath...
我试过了:
NSIndexPath *nextIndexPath = [_collectionView indexPathForItemAtPoint:CGPointMake(25, (_collectionView.frame.size.height-25)*(_currentIndexRowForCellOnScreen+1))];
其中_currentIndexRowForCellOnScreen 是UICollectionView 在屏幕上首次出现的indexPath.row:
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
但是当我把它放进去的时候:
- (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell
它在第一个 Cell 之后返回 NULL,并且不动画......
任何方向将不胜感激。感谢您的宝贵时间。
【问题讨论】:
标签: ios objective-c uiscrollview uicollectionview uicollectionviewcell