iOS UIImageView实现一个呼吸灯、仿华为banner效果

释放双眼,带上耳机,听听看~!

首先感谢华为提供的两张图片


如果冒犯,请联系我删除,谢谢!

  • 开始表演

.h文件

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface AnimationViewController : UIViewController

@end

NS_ASSUME_NONNULL_END

.m文件

#import "AnimationViewController.h"

@interface AnimationViewController ()

@property (nonatomic, strong) UIImageView *img2;
@property (nonatomic) NSInteger time;

@end

@implementation AnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    _time = 2;
    
    UIImageView *img1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 100, 1980 * 0.2, 1080 * 0.2)];
    img1.image = [UIImage imageNamed:@"img0"];
    [self.view addSubview:img1];
    
    _img2 = [[UIImageView alloc]initWithFrame:img1.frame];
    _img2.image = [UIImage imageNamed:@"img1"];
    [self.view addSubview:_img2];
    
    //开始动画
    [self GraduallyDarken];
    
}

#pragma mark - 变暗
-(void)GraduallyDarken{
    
    [UIView animateWithDuration:_time animations:^{
        
        self.img2.alpha = 1;
        self.img2.alpha = 0.1;
        
    } completion:^(BOOL finished) {
        [self GraduallyBrighten];
    }];
    
}

#pragma mark - 变亮
-(void)GraduallyBrighten{
    
    [UIView animateWithDuration:_time animations:^{
        
        self.img2.alpha = 0.1;
        self.img2.alpha = 1;
        
    } completion:^(BOOL finished) {
        [self GraduallyDarken];
    }];
    
}

@end

效果图

呼吸灯.gif

  • 表演结束

全剧终

人已赞赏
iOS文章

iOS 加载SVG图片

2019-12-23 13:52:15

iOS文章

iOS NSData转化成string,返回nil的问题

2019-12-23 14:11:57

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索