iOS仿支付宝点击按钮带波浪效果

- (void)viewDidLoad {
    [super viewDidLoad];
 
    self.view.backgroundColor = [UIColor colorWithRed:35 / 255.0 green:39 / 255.0 blue:63 / 255.0 alpha:1];
    //设置中间点击按钮
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"zhifubao"] forState:UIControlStateNormal];
    [btn sizeToFit];
    btn.center = self.view.center;
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)btnClick:(UIButton *)btn {
    
    for (NSInteger i = 0; i < 10; i++) {
        
        // 1.创建一个圆圈view
        UIView *circleView = [[UIView alloc] init];
        circleView.backgroundColor = [UIColor colorWithRed:0 green:170  / 255.0 blue:238 / 255.0 alpha:1];
        circleView.frame = btn.frame;
        
        //    [self.view addSubview:circleView];
        // 把圆圈添加到控制器的view上并且加上支付宝按钮的上面
        //    [self.view insertSubview:circleView aboveSubview:btn];
        // 在支付宝按钮按钮下面插入一个view
        [self.view insertSubview:circleView belowSubview:btn];
        circleView.layer.cornerRadius = circleView.frame.size.width * 0.5;
   
        circleView.layer.masksToBounds = YES;
        
        // 让每一个圆圈延迟时间不一样
        [UIView animateWithDuration:1.0 delay:i * 0.2 options:0 animations:^{ 
            circleView.transform = CGAffineTransformMakeScale(16, 16);
            circleView.alpha = 0;
        } completion:^(BOOL finished) { 
            [circleView removeFromSuperview];
        }];
    }
}

作者:戴上耳机__世界与我无关
链接:https://www.jianshu.com/p/5e11d20a576d
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/a18339063397/article/details/86217314