Keyframe animation
I'm trying to animate an image along a calculated path. I receive no error from the following code, but the image doesn't animate. Any help?
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.remo开发者_JAVA百科vedOnCompletion = NO;
[rockHand.layer addAnimation:anim forKey:@"pathAnimation"];
Solution: one must place a first point in order to add others, so
CGPathAddLineToPoint(path, nil, x, y);
has to be
CGPathMoveToPoint(path, nil, x, y);
精彩评论