2011-05-09 6 views
0

계산 된 경로를 따라 이미지에 애니메이션을 적용하려고합니다. 다음 코드에서 오류 메시지가 나타나지만 이미지가 움직이지 않습니다. 어떤 도움이 필요합니까?키 프레임 애니메이션

UIImageView *rockHand = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"rockHand" ofType:@"png"]]]; 
rockHand.frame = CGRectMake(260, -8, 59, 66); 
[self.view addSubview:rockHand]; 
[self.rockHands addObject:rockHand]; 

int x = 260; 
int y = -8; 
int spring = 15; 
CGMutablePathRef path = CGPathCreateMutable(); 
CGPathAddLineToPoint(path, nil, x, y); 
for (int i = 0; i < 10; i++) { 
    y += (i*2) - spring; 
    x += (i * -0.3) ; 
    spring--; 
    CGPathAddLineToPoint(path, nil, x, y); 
} 

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
anim.path = path; 
anim.duration = 3; 
anim.fillMode = kCAFillModeForwards; 
anim.calculationMode = kCAAnimationPaced; 
anim.removedOnCompletion = NO; 
[rockHand.layer addAnimation:anim forKey:@"pathAnimation"]; 

답변

1

해결 방법 : 하나는 너무

CGPathAddLineToPoint(path, nil, x, y); 

이 있어야한다, 다른 사람을 추가하기 위해 첫 번째 점을 배치해야합니다

CGPathMoveToPoint(path, nil, x, y); 
관련 문제