2013-06-20 5 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)]; 
시도