ios – 在“CAAnimationGroup”完成后无缝更新图层的可视属性值?

ios – 在“CAAnimationGroup”完成后无缝更新图层的可视属性值?,第1张

概述我试图为比例设置动画然后是CALayer的不透明度,如下所示: CABasicAnimation *scaleUp = [CABasicAnimation animationWithKeyPath:@"transform"];scaleUp.fromValue = [NSValue valueWithCATransform3D:self.timerProgressLayer.transform] 我试图为比例设置动画然后是CALayer的不透明度,如下所示:

CABasicAnimation *scaleUp = [CABasicAnimation animationWithKeyPath:@"transform"];scaleUp.fromValue = [NSValue valueWithCAtransform3D:self.timerProgressLayer.transform];scaleUp.tovalue = [NSValue valueWithCAtransform3D:CAtransform3DMakeScale(1.0,1.0,1.0)];scaleUp.duration = 0.25;scaleUp.fillMode = kCAFillModeForwards;CABasicAnimation *fadeOut = [CABasicAnimation animationWithKeyPath:@"opacity"];fadeOut.fromValue = @(1.0);fadeOut.tovalue = @(0.0);fadeOut.beginTime = 0.3;fadeOut.duration = 0.25;fadeOut.fillMode = kCAFillModeForwards;CAAnimationGroup *group = [CAAnimationGroup animation];group.animations = @[scaleUp,fadeOut];group.removedOnCompletion = YES;group.duration = fadeOut.beginTime + fadeOut.duration;[self.timerProgressLayer addAnimation:group forKey:@"trigger"];

这很简单,动画本身也很好用.但是,在动画结束时,它将被删除,值将恢复为开头的值.为了解决这个问题,我在addAnimation:call之后立即手动设置属性

self.timerProgressLayer.opacity = 0.0;self.timerProgressLayer.transform = CAtransform3DMakeScale(1.0,1.0);

但是,这些调用会覆盖我的动画,图层会淡出并立即缩放.如果我使用动画的委托或[CATransaction setCompletionBlock:]在动画结束时设置属性,很多时候(但不是100%的时间),旧状态的单个帧在结束之间通过动画和正在设置的属性.

如何使用CAAnimationGroup为某些属性设置动画,最后删除动画而不使用旧值查看帧?

解决方法 我以前给过 the long version of this answer.这里没有理由重复详细说明.

但简短的回答是,您看到图层的隐式动画应用于显式动画之上.我之前写过a detailed explanation about implicit and explicit animations and multiple simulations animation,如果你想了解更多关于它的话.

如“长答案”中所述.您的问题的解决方案是更新属性,但暂时禁用隐式动画,以便它们不会应用于您的显式动画:

[CATransaction begin];[CATransaction setdisableActions:YES]; // actions are Disabled for Nowself.timerProgressLayer.opacity = 0.0;self.timerProgressLayer.transform = CAtransform3DMakeScale(1.0,1.0);[CATransaction commit];                // until here
总结

以上是内存溢出为你收集整理的ios – 在“CAAnimationGroup”完成后无缝更新图层的可视属性值?全部内容,希望文章能够帮你解决ios – 在“CAAnimationGroup”完成后无缝更新图层的可视属性值?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1044978.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存