2012-01-27 56 views
0

如何在完成toValue過程後繼續執行UIImageView transform.translation.x動畫:例如:當按下按鈕#1時:從1到55,按下按鈕#2從55到110。 ...如果它在按鈕#2的位置,並且您單擊按鈕#5,然後從55 * 2到55 * 5。CABasicAnimation繼續從值

- (void)animateArrow{ 
CABasicAnimation *theAnimation; 


theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
theAnimation.duration=0.4; 
theAnimation.repeatCount=1; 
theAnimation.toValue=[NSNumber numberWithFloat:50]; 

[buttonArrow.layer setValue:theAnimation.toValue forKey:theAnimation.keyPath]; 
[buttonArrow.layer addAnimation:theAnimation forKey:@"transform.translation.x"]; 

}

回答

1

你應該考慮在一個陣列沿動畫路徑提供多點這樣的:

CAKeyframeAnimation *downMoveAnimation; 
downMoveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"]; 
downMoveAnimation.duration = 12; 
downMoveAnimation.repeatCount = 1; 
downMoveAnimation.values = [NSArray arrayWithObjects:   
          [NSNumber numberWithFloat:20], 
          [NSNumber numberWithFloat:220], 
          [NSNumber numberWithFloat:290], nil]; 
downMoveAnimation.keyTimes = [NSArray arrayWithObjects:  
           [NSNumber numberWithFloat:0], 
           [NSNumber numberWithFloat:0.5], 
           [NSNumber numberWithFloat:1.0], nil]; 

downMoveAnimation.timingFunctions = [NSArray arrayWithObjects: 
             [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],  // from keyframe 1 to keyframe 2 
             [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3 

downMoveAnimation.removedOnCompletion = NO; 
downMoveAnimation.fillMode = kCAFillModeForwards; 

希望這個作品。

基本動畫和關鍵幀動畫之間的主要區別在於,關鍵幀允許您指定沿着路徑的多個點。

+0

謝謝隊友。像魅力工作.. :) – 2014-01-27 05:29:45