【发布时间】:2017-09-06 03:28:37
【问题描述】:
我正在构建一个应用程序,该应用程序将使用简单的 CABasicAnimation 生成一个图像在屏幕上“行走”的动画。我将它设置为在一段时间内步行一定距离,然后停止,直到用户给它更多命令,它会再次继续步行相同的距离和持续时间。我遇到的问题是,第一次之后,图像会停在它应该停在的地方,但它不会继续行走,它会跳回到原来的位置并重新开始。我以为我在原点上正确设置了这个设置,但我想不是。
CABasicAnimation *hover = [CABasicAnimation animationWithKeyPath:@"position"];
hover.fillMode = kCAFillModeForwards;
hover.removedOnCompletion = NO;
hover.additive = YES; // fromValue and toValue will be relative instead of absolute values
hover.fromValue = [NSValue valueWithCGPoint:CGPointZero];
hover.toValue = [NSValue valueWithCGPoint:CGPointMake(110.0, -50.0)]; // y increases downwards on iOS
hover.autoreverses = FALSE; // Animate back to normal afterwards
hover.duration = 10.0; // The duration for one part of the animation (0.2 up and 0.2 down)
hover.repeatCount = 0; // The number of times the animation should repeat
[theDude.layer addAnimation:hover forKey:@"myHoverAnimation"];
【问题讨论】:
标签: ios xcode uiimageview cabasicanimation