我有一个垂直UICollectionView的每个单元占用整个self.view.frame我可以轻松向上滑到页面到下一个单元格,但我想按下一个按钮做同样的事情.
我尝试过使用:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
和:
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
他们工作但他们暂时"白出"当前的Cell以呈现nextCell,而刷卡在转换过程中显示两个单元格.
理想情况下我想使用:
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
但我不知道如何访问nextCell indexPath...我试过:
NSIndexPath *nextIndexPath = [_collectionView indexPathForItemAtPoint:CGPointMake(25, (_collectionView.frame.size.height-25)*(_currentIndexRowForCellOnScreen+1))];
Run Code Online (Sandbox Code Playgroud)
哪里_currentIndexRowForCellOnScreen是indexPath.row对的UICollectionView的屏幕上的首次亮相:
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但当我把它放入:
- (NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell
Run Code Online (Sandbox Code Playgroud)
它在第一个Cell之后返回NULL,并且没有动画....
任何方向将不胜感激.感谢您的时间.
objective-c uiscrollview ios uicollectionview uicollectionviewcell