gpt4 book ai didi

ios - CAAnimationGroup 在完成时恢复到原来的位置

转载 作者:可可西里 更新时间:2023-11-01 17:11:04 27 4
gpt4 key购买 nike

在 iOS 中,我试图创建一个图标缩小的效果,然后在屏幕上呈弧形飞行,同时淡出,然后消失。我已经使用 CAAnimationGroup 实现了这 3 种效果,它可以满足我的要求。问题是当动画结束时, View 出现在原来的位置,全尺寸和完全不透明。谁能在下面的代码中看到我做错了什么?动画不应该恢复到原来的位置,而是在结束时消失。

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;
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];

最佳答案

我认为您需要将动画的 fillMode 属性设置为 kCAFillModeForwards。那应该在结束时卡住动画。另一个建议(老实说,这是我通常会做的)是在设置动画后将图层本身的属性设置到它们的最终位置。这样,当动画被移除时,图层仍将具有最终属性作为其模型的一部分。

顺便说一句,CAAnimationGroup 中包含的动画的removedOnCompletion 标志被忽略。您可能应该删除这些分配,因为它们具有误导性。将它们替换为上面指定的 fillMode 的赋值。

关于ios - CAAnimationGroup 在完成时恢复到原来的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7421669/

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