首先查看效果图
逻辑比较简单,直接上淡入淡如切换图片的核心代码,
这里通过在设置切换图片的时候,添加一个动画来实现淡如淡出的
效果,
-(void)displayUrlImage {
if (self.urls.count == 0) {
return;
}
self.index ++;
if (self.index >= [self.urls count]) {
self.index = 0;
}
CATransition *animation = [CATransition animation];
animation.duration = 1.2f ;
animation.fillMode = kCAFillModeForwards;
animation.type = kCATransitionFade;
[self.imgView.layer addAnimation:animation forKey:@"animationID"];
NSString *url = self.urls[self.index];
[self.imgView sd_setImageWithURL:[NSURL URLWithString:url]];
}
使用方法
pod ‘LBFadeImageLoopView’
使用方法
- (LBFadeImageLoopView *)fadeView
{
if (!_fadeView) {
_fadeView = [[LBFadeImageLoopView alloc] init];
_fadeView.stayTimeInterval = 2;
_fadeView.fadeTime = 0.5;
_fadeView.delegate = self;
}
return _fadeView;
}
NSArray *images = @[[UIImage imageNamed:@"1"], [UIImage imageNamed:@"2"], [UIImage imageNamed:@"3"]];
[self.fadeView loadWithImages:images];
#pragma mark - LBFadeImageLoopViewDelegate
- (void)fadeLoopView:(LBFadeImageLoopView *)fadeLoopView clickItemAtIndex:(NSInteger)index
{
NSLog(@"啦啦啦阿拉点击点击的第%ld张图片", index);
}