关键帧动画
我正在尝试沿着计算的路径对图像进行动画处理。我从以下代码中没有收到任何错误,但图像没有动画。有什么帮助吗?
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"];
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.removedOnCompletion = NO;
[rockHand.layer addAnimation:anim forKey:@"pathAnimation"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:必须放置第一个点才能添加其他点,因此
必须
Solution: one must place a first point in order to add others, so
has to be