iOS – CAANIMATIONGROUP is restored to the original location when completed

In iOS, I tried to create an icon effect that shrinks the icon, and when it gradually disappears, it flies across the screen in an arc, and then disappears. I have used CAAnimationGroup to achieve these three effects , It can achieve the effect I want. The problem is that when the animation ends, the view is displayed in its original position, full size and full opacity. Can anyone see what I am doing wrong in the code below?
The animation should not be restored to its original position, but disappear at the end.

UIBezierPath *movePath = [UIBezierPath bezierPath];
CGPoint libraryIconCenter = CGPointMake(610, 40);

CGPoint ctlPoint = CGPointMake(self.imgViewCropped.center.x, 22.0);
movePath moveToPoint:self.imgViewCropped.center];
[movePath addQuadCurveToPoint:libraryIconCenter
controlPoint:ctlPoint];

CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;< br /> moveAnim.removedOnCompletion = NO;

CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = NO;

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim .fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.0];
opacityAnim.removedOnCompletion = NO;

CAAnimationGroup *animGroup = [CAAnimationGroup animation ];
animGroup.animations = [NSArray arrayWithObjects:moveAnim,scaleAnim,opacityAnim, nil];
animGroup.duration = 0.6;
animGroup.delegate = self;
animGroup.removedOnCompletion = NO;
[self.imgViewCropped.layer addAnimation:animGroup forKey:nil];

I believe you need to set the fillMode property of the animation to kCAFillModeForwards. This should freeze the animation at the end. Another suggestion (which is honestly what I usually do) is just to set the properties of the layer itself to Their final position. This way, when the animation is removed, the layer still has the final properties as part of its model.

Also, ignore the removedOnCompletion flag of the animation contained in the CAAnimationGroup. You may just Delete these assignments because they are misleading. Replace them with the fillMode assignment, as described above.

In iOS, I am trying to create an icon effect that shrinks the icon , And fly across the screen in an arc when it gradually disappears, and then disappear. I have used CAAnimationGroup to achieve these three effects, and it can achieve the effect I want. The problem is that when the animation ends, the view is displayed in the original position, complete Size and full opacity. Can anyone see what I am doing wrong in the code below?
The animation should not be restored to its original position, but disappear at the end.

UIBezierPath *movePath = [UIBezierPath bezierPath];
CGPoint libraryIconCenter = CGPointMake(610, 40);

CGPoint ctlPoint = CGPointMake(self.imgViewCropped.center.x, 22.0);
movePath moveToPoint:self.imgViewCropped.center];
[movePath addQuadCurveToPoint:libraryIconCenter
controlPoint:ctlPoint];

CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;< br /> moveAnim.removedOnCompletion = NO;

CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = NO;

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fr omValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.0];
opacityAnim.removedOnCompletion = NO;

CAAnimationGroup *animGroup = [CAAnimationGroup animation] ;
animGroup.animations = [NSArray arrayWithObjects:moveAnim,scaleAnim,opacityAnim, nil];
animGroup.duration = 0.6;
animGroup.delegate = self;
animGroup.removedOnCompletion = NO;
[self.imgViewCropped.layer addAnimation:animGroup forKey:nil];

I believe you need to set the fillMode property of the animation to kCAFillModeForwards This should freeze the animation at the end. Another suggestion (and honestly, this is what I usually do) is just to set the properties of the layers themselves to their final positions after you set up the animation. This way, when the animation is removed, The layer still has the final properties as part of its model.

Also, ignore the removedOnCompletion flag of the animation contained in the CAAnimationGroup. You may just delete these jobs because they are misleading. Replace them Assign a value to fillMode, as described above.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3869 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.