封装了一个iOS淡入淡出切换图片的组件

首先查看效果图
请添加图片描述

逻辑比较简单,直接上淡入淡如切换图片的核心代码,
这里通过在设置切换图片的时候,添加一个动画来实现淡如淡出的
效果,

-(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);
}

demo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值