首页 > 代码库 > 三个ImageView 实现无线轮播 方法
三个ImageView 实现无线轮播 方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { //开始滚动,判断位置,然后替换复用的三张图 [self changeImageWithOffset:scrollView.contentOffset.x]; } - (void)changeImageWithOffset:(CGFloat)offsetX { if (offsetX >= ScrollWidth * 2) { _currentIndex++; if (_currentIndex == _MaxImageCount-1) { [self changeImageLeft:_currentIndex-1 center:_currentIndex right:0]; }else if (_currentIndex == _MaxImageCount) { _currentIndex = 0; [self changeImageLeft:_MaxImageCount-1 center:0 right:1]; }else { [self changeImageLeft:_currentIndex-1 center:_currentIndex right:_currentIndex+1]; } _PageControl.currentPage = _currentIndex; } if (offsetX <= 0) { _currentIndex--; if (_currentIndex == 0) { [self changeImageLeft:_MaxImageCount-1 center:0 right:1]; }else if (_currentIndex == -1) { _currentIndex = _MaxImageCount-1; [self changeImageLeft:_currentIndex-1 center:_currentIndex right:0]; }else { [self changeImageLeft:_currentIndex-1 center:_currentIndex right:_currentIndex+1]; } _PageControl.currentPage = _currentIndex; } }
#pragma mark - 给复用的imageView赋值 - (void)changeImageLeft:(NSInteger)LeftIndex center:(NSInteger)centerIndex right:(NSInteger)rightIndex { if (_isNetworkImage) { [_leftImageView sd_setImageWithURL:[NSURL URLWithString:_imageArray[LeftIndex]] placeholderImage:_placeholderImage]; [_centerImageView sd_setImageWithURL:[NSURL URLWithString:_imageArray[centerIndex]] placeholderImage:_placeholderImage]; [_rightImageView sd_setImageWithURL:[NSURL URLWithString:_imageArray[rightIndex]] placeholderImage:_placeholderImage]; }else { _leftImageView.image = _imageArray[LeftIndex]; _centerImageView.image = _imageArray[centerIndex]; _rightImageView.image = _imageArray[rightIndex]; } [_scrollView setContentOffset:CGPointMake(ScrollWidth, 0)]; }
三个ImageView 实现无线轮播 方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。