我有一个集合视图,显示3个单元格可见。当我单击右箭头按钮时,它应该滚动显示接下来的3个单元格,当我单击左箭头按钮时,它应滚动显示前3个单元格。如果后面有2个单元格,它应该显示那些具有前一个最后一个可见单元格的2个单元格。
有人可以帮忙吗?
答案 0 :(得分:0)
你只需要做
[self.collectionView scrollToItemAtIndexPath:nextItem atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
您需要为要滚动的下一个项目传递indexpath
答案 1 :(得分:0)
I have found the solution.
- (void)viewDidLoad
{
oldrow=0;
}
- (IBAction)right_button:(id)sender
{
NSIndexPath *newIndexPath;
if (xr-1>0) {
oldsection = 0;
newIndexPath = [NSIndexPath indexPathForRow:oldrow+3 inSection:0];
oldrow=oldrow+3;
[collection_vw scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
xr--;
xl++;
}
else if (y>0)
{
[_btn_right setHidden:YES];
oldsection = 0;
newIndexPath = [NSIndexPath indexPathForRow:array_stories.count-3 inSection:0];
oldrow=array_stories.count-3;
[collection_vw scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}
}
where
xr=array_stories.count/3;
xl=0;
y=array_stories.count%3;