2013-06-20 26 views
1

我是iOS開發新手。我正在創建一個用於旋轉圖像的關鍵幀動畫。圖像成功地向前旋轉。我想要將圖像全部向後旋轉。如何使用CAKeyFrameAnimation向後動畫圖像

這是我的代碼。

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)]; 
tempView.image = [UIImage imageNamed:@"1_03.png"]; 
[self.view addSubview:tempView]; 

const NSUInteger rotations = 1; 
const NSTimeInterval duration = 4.0f; 

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"]; 
CGFloat touchUpStartAngle = 0; 
CGFloat touchUpEndAngle = (M_PI); 
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI)/duration; 
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle + angularVelocity * duration)]; 
anim.duration = duration; 
anim.delegate = self; 
anim.repeatCount = INFINITY; 
[tempView.layer addAnimation:anim forKey:@"animation"]; 

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +  (touchUpEndAngle)); 

如何做到這一點。

回答

3

試試這個。

UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(28,158,133,133)]; 
tempView.image = [UIImage imageNamed:@"1_03.png"]; 
[self.view addSubview:tempView]; 

const NSUInteger rotations = 1; 
const NSTimeInterval duration = 4.0f; 

CAKeyframeAnimation *anim = [CAKeyframeAnimation  animationWithKeyPath:@"transform.rotation"]; 
CGFloat touchUpStartAngle = 0; 
CGFloat touchUpEndAngle = (M_PI); 
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI)/duration; 
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle - angularVelocity * duration)]; 
anim.duration = duration; 
anim.delegate = self; 
anim.repeatCount = INFINITY; 
[tempView.layer addAnimation:anim forKey:@"animation"]; 

tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle +  (touchUpEndAngle)); 
1

試試這個

CGFloat touchUpStartAngle = 0; 
CGFloat touchUpEndAngle = (M_PI); 
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI)/duration; 
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle - angularVelocity * duration)]; 
相關問題