int i; -(UIButton *)praiseBtn { if (!_praiseBtn) { _praiseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_praiseBtn setBackgroundImage:[UIImage imageNamed:@"未选点赞"] forState:UIControlStateNormal]; [_praiseBtn setBackgroundImage:[UIImage imageNamed:@"已选点赞"] forState:UIControlStateSelected]; [_praiseBtn addTarget:self action:@selector(praiseAction:) forControlEvents:UIControlEventTouchUpInside]; } return _praiseBtn; } #pragma mark - 点赞按钮事件 -(void)praiseAction:(UIButton *)sender { if (sender.selected) { [Dialog toastCenter:@"您已经赞过"]; return; } else { sender.selected = YES; //点赞动画 CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; k.values = @[@(0.1),@(1.0),@(1.5)]; k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)]; k.calculationMode = kCAAnimationLinear; i++; [sender.layer addAnimation:k forKey:@"SHOW"]; } }