2

我試圖沿着彎曲的路徑動畫視圖和規模下來同時:CAAnimationGroup與CAKeyframeAnimation和CABasicAnimation

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"]; 

的問題是,縮小逐漸因爲它的動作,而不是圖,它會立即縮小,然後沿着路徑移動。當它明顯移動時,我需要縮小比例。

回答

1

解決做這個:

resizeAnimation.fromValue = [NSNumber numberWithDouble:1.0]; 

我不明白爲什麼我必須這樣做。似乎它應該從當前變換的默認值fromValue開始。