心跳动画
- (void)viewDidLoad { [super viewDidLoad]; UIButton *heart = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width * 0.5 - 25, 200, 50, 50)]; [self.view addSubview:heart]; [heart setImage:[UIImage imageNamed:@"5_heart"] forState:UIControlStateNormal]; [heart setImage:[UIImage imageNamed:@"5_heart_clicked"] forState:UIControlStateSelected]; [heart addTarget:self action:@selector(heartButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } /** * 心跳 */ - (void)heartButtonClick:(UIButton *)button{ button.selected = !button.selected; 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; [button.layer addAnimation:k forKey:@"SHOW"]; }