【问题标题】:CAShapeLayer’s strokeEnd doesn’t animateCAShapeLayer 的 strokeEnd 没有动画
【发布时间】:2015-03-15 01:39:49
【问题描述】:

这是我用来为 CAShapeLayer 设置动画的代码:

_progressBarLayer.strokeEnd = CGFloat(_progressToDrawForProgress(progress))

let progressAnimation = CABasicAnimation(keyPath: "strokeEnd")
progressAnimation.duration = CFTimeInterval(1.0)
progressAnimation.fromValue = CGFloat(self.progress)
progressAnimation.toValue = _progressBarLayer.strokeEnd
progressAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)

_progressBarLayer.addAnimation(progressAnimation, forKey: "progressAnimation")

我已经使用委托进行了测试,以查看动画是否播放,并且确实可以播放。记录在正确的位置开始和停止。

此代码在 setProgress(progress: CGFloat, animated: Bool) 函数中,如果动画为真,则运行。

这里有什么明显的地方吗?

【问题讨论】:

  • 仅供参考,_progressBarLayer 是一个懒惰的 CAShapeLayer 属性
  • 会发生什么?什么都没有,还是立即跳到最终值?测试时CGFloat(self.progress)和_progressBarLayer.strokeEnd有什么值?

标签: ios animation cabasicanimation cashapelayer


【解决方案1】:

长答案:事实证明,动画没有播放是因为使用石英在 CAShapeLayer 上方绘制了一些东西,所以我认为 CAShapeLayer(应该是动画的)实际上是同一层的 Quartz 绘图。

简答:不要使用 Quartz 绘制到图形上下文

【讨论】:

  • 你是如何制作动画的?你用过 CABasicAnimation 以外的东西吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-28
  • 2014-09-19
  • 1970-01-01
  • 2014-03-08
相关资源
最近更新 更多