Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 向翻转动画添加反弹效果_Ios_Objective C_Animation_Cabasicanimation - Fatal编程技术网

Ios 向翻转动画添加反弹效果

Ios 向翻转动画添加反弹效果,ios,objective-c,animation,cabasicanimation,Ios,Objective C,Animation,Cabasicanimation,我为我的饼图制作了翻转动画。这是我的密码“ animationDidStop:finished: CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"]; animation.fromValue = [NSNumber numberWithFloat:0.5]; animation.toValue = [NSNumber numberWithFloat:1.0]; ani

我为我的饼图制作了翻转动画。这是我的密码“

animationDidStop:finished:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
animation.fromValue = [NSNumber numberWithFloat:0.5];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.duration = 1.0f;
[self.pieChart addAnimation:animation forKey:@"scale"];

如何将反弹效果添加到第二个动画中?(
animationDidStop:finished:

使用
CAKeyFrameAnimation
而不是两个
CABasicAnimation

CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"];
scaleAnimation.keyTimes = @[@(0), @(0.5), @(0.9), @(1)];
scaleAnimation.values = @[@(1.0), @(0.5), @(1.1), @(1.0)];
scaleAnimation.duration = 1.0f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
使用
keyTimes
values
,您可以在动画中指定多个姿态。在这里,我让它以1的比例开始,动画比例为0.5(您的第一个动画值),然后是1.1(创建“反弹”的超调),最后是1(您的第二个动画值)。根据您的喜好调整它们

如果要分两部分执行此动画,可以保留第一个动画,然后在
animationDidStop:finished:
中启动
CAKeyFrameAnimation
,类似于此:

CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"];
scaleAnimation.keyTimes = @[@(0), @(0.8), @(1)];
scaleAnimation.values = @[@(0.5), @(1.1), @(1.0)];
scaleAnimation.duration = 1.0f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

如果改为使用UIView动画块,则需要执行以下类似操作:

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
    self.squareView.transform = CGAffineTransformMakeScale(0.5, 1);
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
        self.squareView.transform = CGAffineTransformIdentity;
    } completion:nil];
}];

您可能需要使用参数来调整动画。

谢谢!!是否可以在
[UIView animateWithDuration…]
中执行此操作?@Jessica我编辑了我的答案,以提供一个备选方案,使用两个
CAAnimation
,另一个使用
UIView
动画块(您需要两个)。
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
    self.squareView.transform = CGAffineTransformMakeScale(0.5, 1);
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
        self.squareView.transform = CGAffineTransformIdentity;
    } completion:nil];
}];