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