UIButton Scale动画不再适用

时间:2015-06-17 16:05:15

标签: ios objective-c animation uibutton cgaffinetransform

感谢您的帮助!

这是我的问题:

我有一个动画方法:

-(void) animateButtonDown {

// Animation for cornerRadius
[self.playStopButton setTitle:@"" forState: UIControlStateNormal];
CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
morph.fromValue = @42.5;
morph.toValue = @0;
morph.duration = 0.5;
[self.playStopButton.layer addAnimation:morph forKey:@"morph"];
playStopButton.layer.cornerRadius = 0;

//Animation for scale and color
playStopButton.transform = CGAffineTransformMakeScale(1,1);
[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:0.5];
    playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
    playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
[UIView commitAnimations]; }

动画效果很好。现在,用于转换比例因子的动画不再起作用。这似乎是整个构造:

playStopButton.transform = CGAffineTransformMakeScale(1,1);
[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:0.5];
    playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
    playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
[UIView commitAnimations];

不再起作用了。它直接跳转到(0.6,0.6)......这是首次通过xCode 6.1.3的更新来识别。

我需要一个持续时间为0.5的平滑缩放变换动画。

我希望有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

尝试使用动画块,可能会起作用

[UIView animateWithDuration:0.5 animations:^{
  playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
  playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
}];