先在storyboard中設(shè)置view的背景顏色
在viewDidLoad中創(chuàng)建按鈕UI布局如下:
- (void)setupUI{
//1.創(chuàng)建一個按鈕
UIButton *button = [[UIButton alloc]init];
//2.設(shè)置按鈕的屬性
[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];
}
- 點擊按鈕循環(huán)擴(kuò)散圓并逐漸透明
- (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);
//設(shè)置透明度
circleView.alpha = 0;
} completion:^(BOOL finished) {
//動畫結(jié)束以后執(zhí)行的操作
[circleView removeFromSuperview];
count ++;
if (count == 7) {
sender.enabled = YES;
}
}];
}
}
補充:創(chuàng)建圓的方法
- (UIView *)circleView{
//創(chuàng)建一個圓形的視圖
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;
}
這就完成了簡單實現(xiàn)!