ios - 在动画完成之前更改 CALayer 内容
<p><p>我正在开发一个实现翻转卡片时钟动画的 UI 组件。一切正常,但是当我将顶级 CALayer 内容更改为新图像时,旧图像在更改之前保持可见。它会产生混淆效果。为了更好地解释,我将 gif 动画放在下面:</p>
<p> <a href="/image/KyBTA.gif" rel="noreferrer noopener nofollow"><img src="/image/KyBTA.gif" alt="enter image description here"/></a> </p>
<p>这是更改 CALayer 内容的代码:</p>
<pre><code>firstTopLayer.contents = secondTopLayer.contents
let bottomAnim = CABasicAnimation(keyPath: "transform")
bottomAnim.duration = animDuration/2
bottomAnim.repeatCount = 1
bottomAnim.fromValue = NSValue.init(caTransform3D:
CATransform3DMakeRotation((CGFloat)(M_PI_2), 1, 0, 0))
bottomAnim.toValue = NSValue.init(caTransform3D:
CATransform3DMakeRotation(0, 1, 0, 0))
bottomAnim.isRemovedOnCompletion = true
bottomAnim.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseIn)
firstBottomLayer.add(bottomAnim, forKey: "bottom")
firstBottomLayer.contents = self.bufferContents
</code></pre>
<p>欲了解更多信息,我将链接指向 <a href="https://github.com/ftp27/FTPFlipNumber/blob/master/FTPFlipNumber/Classes/FTPFlipNumber.swift#L151-L168" rel="noreferrer noopener nofollow">repository</a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我找到了解决方案。顶级动画必须有这个配置</p>
<pre><code>topAnim.fillMode = kCAFillModeForwards
topAnim.isRemovedOnCompletion = false
</code></pre>
<p>在每次开始这个动画之后。 </p>
<pre><code>firstTopLayer.removeAnimation(forKey: kTopAnimaton)
</code></pre>
<p>使用此配置,顶层保持在最后一帧动画位置</p></p>
<p style="font-size: 20px;">关于ios - 在动画完成之前更改 CALayer 内容,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41806611/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41806611/
</a>
</p>
页:
[1]