Intermittent fillMode = kCAFillModeForwards error using CAKeyframeAnimation with path

I have an intermittent issue where I move a UIImageView around the screen using CAKeyframeAnimation. I want the UIImageView position to stay where the animation ends when it runs. This error occurs only for certain start and end points. When I use random points, it works correctly most of the time, but in about 5-15% of cases when it fails, it returns to the position of preliminary animation. The problem only occurs when using CAKeyframeAnimation using the path property. If I use the values ​​property, the error does not appear. I set removeOnCompletion = NO, and fillMode = kCAFillModeForwards. I posted a link to the test Xcode below. Here is my code for tweaking the animation. I have a usePath property. When it is YES, an error appears.When I set usePath to NO, a binding error does not occur. In this case, I use a path that is a simple string, but as soon as I resolve this error with a simple path, I will use a more complex path with curves in it.

// 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 goto (http://www.24x7digital.com/downloads/PathFillModeBug.zip)

" ", . , - . , usePath YES NO. usePath - , . usePath , .

SDK 3.1.3, , SDK 3.0, Sim iPhone.

, , - , . , .

+3
1

idp-dts@apple.com , Core Animation kCAFillModeForwards . , (ID : 7797921).

. pt . , :

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

rotationMode = kCAAnimationRotateAuto, z , . , , rotationMode z . DidStop: : :

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

, , . , fillMode = kCAFillModeForwards .

+7

Source: https://habr.com/ru/post/1736736/


All Articles