1、// 设置uicollection 的 横向滑动flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
2、// 源数据首位 添加数组最后的元素 [self.dataArray addObject:_array.lastObject];
// 源数据末尾 补充第一个元素 [self.dataArray addObject:_array.firstObject];
3、设置scrollView Delegate方法:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView == self.collectionView) {
//如果滑动到倒数第一张。则collection滚动到第二张
if(scrollView.contentOffset.x == (self.dataArray.count-1)*(self.frame.size.width) ) {
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:false];
}
//如果滑动到第一张。则collection滚动倒数第一张
else if(scrollView.contentOffset.x ==0){
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:(self.dataArray.count-2) inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:false];
}else{
// 正常滚动 }
}
}
网友评论