先在storyboard中设置view的背景颜色
在viewDidLoad中创建按钮UI布局如下:
- (void)setupUI{
//1.创建一个按钮
UIButton *button = [[UIButton alloc]init];
//2.设置按钮的属性
[button setBackgroundImage:[UIImage imageNamed:@"alipay_msp_op_success"] forState:UIControlStateNormal];
[button sizeToFit];
button.center = self.view.center;
[button addTarget:self action:@selector(startXiuXiu:) forControlEvents:UIControlEventTouchUpInside];
//3.把按钮添加到父控件上显示
[self.view addSubview:button];
[self circleView];
}
- 点击按钮循环扩散圆并逐渐透明
- (void)startXiuXiu:(UIButton *)sender{
sender.enabled = NO;
__block NSInteger count = 0;
for (NSInteger i = 0; i<8; i++) {
UIView *circleView = [self circleView];
circleView.backgroundColor = [UIColor colorWithRed:70 / 255.0 green:105 / 255.0 blue:146 / 255.0 alpha:1.0];
[UIView animateWithDuration:8 delay:i options:0 animations:^{
circleView.transform = CGAffineTransformMakeScale(8, 8);
//设置透明度
circleView.alpha = 0;
} completion:^(BOOL finished) {
//动画结束以后执行的操作
[circleView removeFromSuperview];
count ++;
if (count == 7) {
sender.enabled = YES;
}
}];
}
}
补充:创建圆的方法
- (UIView *)circleView{
//创建一个圆形的视图
UIView *circleView = [[UIView alloc]init];
circleView.center = self.view.center;
circleView.bounds = CGRectMake(0, 0, 100, 100);
// circleView.frame = CGRectMake(0, 0, 100, 100);
//切一个圆形的视图。圆角半径等于宽高的一半
circleView.layer.cornerRadius = 50;
//给一个自定义的颜色
circleView.backgroundColor = [UIColor colorWithRed:85/255.0 green:166/255.0 blue:238/255.0 alpha:1];
// [self.view addSubview:circleView];
[self.view insertSubview:circleView atIndex:0];
return circleView;
}
这就完成了简单实现!