收藏按钮的点击效果

先建个结构体属性: 

{int i; UIButton *button;} 

创建个按钮:

button= [[UIButton alloc] initWithFrame:CGRectMake(100,300,20,20)];

[button setImage:[UIImage imageNamed:@"收藏Normal"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"收藏Selected"] forState:UIControlStateSelected];

[button addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

实现方法:

-(void)change:(UIButton*)sender {

[button setImage:[UIImage imageNamed:(i%2==0?@"收藏Selected":@"收藏Normal")]forState:UIControlStateNormal];

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++;

[button.layer addAnimation:kforKey:@"SHOW"];

}

OK。

你可能感兴趣的:(收藏按钮的点击效果)