gpt4 book ai didi

iphone - 使用 CAKeyframeAnimation 和路径时出现间歇性 fillMode=kCAFillModeForwards 错误

转载 作者:行者123 更新时间:2023-12-03 19:35:36 26 4
gpt4 key购买 nike

当我使用 CAKeyframeAnimation 在屏幕上移动 UIImageView 时遇到间歇性问题。我希望 UIImageView 的位置保持在动画完成时结束的位置。此错误仅发生在某些起点和终点。当我使用随机点时,它在大多数情况下都能正常工作,但大约 5-15% 的情况下它会失败并恢复到动画前的位置。仅当使用 CAKeyframeAnimation 使用路径属性时才会出现该问题。如果我使用值属性,则不会出现错误。我设置removedOnCompletion = NO,并且fillMode = kCAFillModeForwards。我在下面发布了一个测试 Xcode 的链接。这是我设置动画的代码。我有一个属性 usePath.当这是"is"时,就会出现错误。当我将 usePath 设置为 NO 时,不会发生快速恢复错误。在本例中,我使用的路径是一条简单的直线,但是一旦我用简单的路径解决了这个错误,我将使用一条包含曲线的更复杂的路径。

// create the point        
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
if (self.usePath) {
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startPt.x, startPt.y);
CGPathAddLineToPoint(path, NULL, endPt.x, endPt.y);
moveAnimation.path = path;
CGPathRelease(path);
} else {
moveAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:startPt],
[NSValue valueWithCGPoint:endPt],
nil];
}
moveAnimation.calculationMode = kCAAnimationPaced;
moveAnimation.duration = 0.5f;
moveAnimation.removedOnCompletion = NO;
// leaves presentation layer in final state; preventing snap-back to original state
moveAnimation.fillMode = kCAFillModeForwards;
moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
// moveAnimation.delegate = self;

// start the animation
[ball.layer addAnimation:moveAnimation forKey:@"moveAnimation"];

要 dl 并查看我的测试项目,请转到 test project (http://www.24x7digital.com/downloads/PathFillModeBug.zip)

点击“移动球”按钮开始播放球的动画。我已经硬编码了一个起点和终点,这导致每次都会发生错误。使用开关将 usePath 更改为 YES 或 NO。当 usePath 为 YES 时,您将看到快照返回错误。当 usePath 为 NO 时,您将不会看到回弹错误。

我使用的是 SDK 3.1.3,但我在使用 SDK 3.0 时也发现了此错误,并且在 Sim 和 iPhone 上也发现了此错误。

任何有关如何解决此问题或我是否做错了什么的想法都将受到赞赏。谢谢,马克。

最佳答案

联系 idp-dts@apple.com 后,他们确认 Core Animation 中存在关于路径 kCAFillModeForwards 的错误。他们让我提交错误报告,我照做了(问题 ID:7797921)。

他们确实尝试给我一个解决方法。他们说在我开始动画后立即设置结束点位置。这将防止错误发生时位置回弹:

// start the animation
[ball.layer addAnimation:moveAnimation forKey:@"moveAnimation"];
ball.layer.position = endPt;

但在我的实际应用程序中,我设置了rotationMode = kCAAnimationRotateAuto,以便更新对象的z旋转以保持其与路径相切。因此,当发生快速恢复时,rotationMode z 旋转就会丢失。他们告诉我在animationDidStop:finished:中明确设置旋转:像这样:

[ball.layer setValue:[NSNumber numberWithDouble:-M_PI/2.0] forKeyPath:@"transform.rotation.z"];

这并不能完全解决问题,因为有时我会看到快速返回旋转的闪烁,然后是校正旋转。我希望他们修复 fillMode = kCAFillModeForwards 的路径错误。

关于iphone - 使用 CAKeyframeAnimation 和路径时出现间歇性 fillMode=kCAFillModeForwards 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2436596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com