ios - CAAnimationGroup 与 CAKeyframeAnimation 和 CABasicAnimation

标签 ios uiview cabasicanimation caanimation cakeyframeanimation

我正在尝试沿曲线路径设置 View 动画并同时缩小它:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = NO;
    //Setting Endpoint of the animation
    CGPoint endPoint = endCenter;
    CGMutablePathRef curvedPath = CGPathCreateMutable();
    CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
    CGPathAddCurveToPoint(curvedPath, NULL, viewOrigin.x+200, viewOrigin.y-150, endPoint.x+100, endPoint.y+10, endPoint.x, endPoint.y);
    pathAnimation.path = curvedPath;
    CGPathRelease(curvedPath);

    // Set up scaling
    CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    resizeAnimation.toValue = [NSNumber numberWithDouble:0.4];
    resizeAnimation.fillMode = kCAFillModeForwards;
    resizeAnimation.removedOnCompletion = NO;

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.fillMode = kCAFillModeForwards;
    group.removedOnCompletion = YES;
[group setAnimations:[NSArray arrayWithObjects: pathAnimation, resizeAnimation, nil]];
    group.duration = 3.7f;
    group.delegate = self;
    [group setValue:self.myView forKey:@"imageViewBeingAnimated"];

self.myView.center = endCenter;
self.myView.transform = self.myViewTransform;
[self.myView.layer addAnimation:group forKey:@"savingAnimation"];

问题是 View 不是在移动时逐渐缩小,而是立即缩小,然后沿着路径移动。当它明显移动时,我需要缩小。

最佳答案

通过这样做解决:

resizeAnimation.fromValue = [NSNumber numberWithDouble:1.0];

我不明白为什么我必须这样做。似乎它应该从当前转换的默认 fromValue 开始。

关于ios - CAAnimationGroup 与 CAKeyframeAnimation 和 CABasicAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982509/

相关文章:

ios - UIView addSubview 自动布局不工作

ios - 旧的 swift 代码不起作用(动画 UIView)

cocoa-touch - 在 View 上显示UIBezierPath

ios - 使用 CABasicAnimation 滚动图像数组

ios - 循环视频 KUDAN AR

objective-c - 旋转后重新组织 View 中元素的最佳方法是什么?

ios - strokeEnd 上的 CABasicAnimation

iOS:对于 64 位上的 Core Animation 问题,是否有任何解决方案?

ios - 用于设计屏幕外 subview 的 Storyboard

ios - 是否可以添加一个 UIView 作为 UINavigationBar 的背景