一个心跳的动画
- (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"];
}
本文介绍了一个简单的心跳动画实现方法,通过iOS应用中的UIButton组件结合Core Animation来制作动态效果。代码中详细展示了如何设置按钮的位置、大小及图片资源,并通过添加目标动作实现了点击时的动画效果。
3596

被折叠的 条评论
为什么被折叠?



