小编Mar*_*4x7的帖子

使用CAKeyframeAnimation和path的间歇fillMode = kCAFillModeForwards错误

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

// 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 …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation iphone-sdk-3.0 cakeyframeanimation

3
推荐指数
1
解决办法
1862
查看次数