咻一咻的簡單實現

  1. 先在storyboard中設置view的背景顏色

  2. 在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];
    
}
  1. 點擊按鈕循環擴散圓并逐漸透明
- (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;
}

這就完成了簡單實現!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容