Ios CAKeyFrameAnimation:在何处/如何设置最终位置/比例?

Ios CAKeyFrameAnimation:在何处/如何设置最终位置/比例?,ios,iphone,core-animation,cakeyframeanimation,Ios,Iphone,Core Animation,Cakeyframeanimation,我正在尝试使用下面的代码使按钮在触摸时收缩/展开 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [touches anyObject]; UIView *view = [myTouch view]; view.transform = CGAffineTransformMakeScale(0.7, 0.7);<--IS THIS c

我正在尝试使用下面的代码使按钮在触摸时收缩/展开

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *myTouch =  [touches anyObject];
    UIView *view = [myTouch view];    
    view.transform = CGAffineTransformMakeScale(0.7, 0.7);<--IS THIS correct??
    CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    scale.duration = 0.8;
    scale.values =   @[@1.0, @0.7,  @0.9, @0.7,  @0.8, @0.7];
    scale.keyTimes = @[@0.13, @0.26, @0.39, @0.52, @0.65, @0.8];
    scale.repeatCount = 1;
    scale.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [view.layer addAnimation:scale forKey:@"scaleAnimation"];
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
{
UITouch*myTouch=[触摸任何对象];
UIView*视图=[myTouch视图];

view.transform=CGAffineTransformMakeScale(0.7,0.7);我不会使用您编写的任何代码

看起来您正试图“反弹”按钮的比例,因此看起来用户对其进行了物理影响

为此,可以使用现代的基于块的动画,特别是使用弹簧阻尼创建动画曲线的新版本(到iOS7)

这会给它带来反弹的效果(但你需要把数字弄对)

您可以在此处阅读有关此函数的更多信息


这是让按钮振荡的完美解决方案。但是我如何获得最终比例并据此设置按钮大小?现在它正在弹回到原始大小。我尝试在完成块中将转换设置为0.5,但这不起作用-谢谢..@iphone noob它应该使用t保持0.7的比例他的方法。这改变了比例,就像做
view.transform=…
一样,它只是给它设置了动画。如果你删除了动画内容,然后在上面设置了变换,会发生什么?我为同一个按钮设置了大约3个动画,一旦我禁用了另外两个,它就如预期的那样工作。两个动画之间的交互导致了他的问题。但这是一个单独的问题。:-)感谢您提供了这个简单的解决方案。我将接受您的回答。如果您在其他动画中的按钮上设置了一个新的变换,那么它将删除缩放变换。
1. Where should I try to permanently change the layers scale? TouchesBegan? TouchesEnded? 

2. How should I do that? (see "<=== Is this correct?" line)
[UIView animateWithDuration:0.8
                      delay:0.0
     usingSpringWithDamping:0.0 // mess around with this
      initialSpringVelocity:0.0 // and this
                    options:0
                 animations:^{
                     view.transform = CGAffineTransformMakeScale(0.7, 0.7);
                 }
                 completion:^(BOOL finished){
                     // if you want to reset the button do it here
                 }];