美文网首页
iOS 暂停和恢复CoreAnimation层动画

iOS 暂停和恢复CoreAnimation层动画

作者: ldjhust | 来源:发表于2015-09-04 12:03 被阅读299次

暂停动画:

func pauseAnimation(layer: CALayer) {

  let timePause = layer.convertTime(CACurrentMediaTime(), nil)

  layer.speed = 0.0

  layer.timeOffset = timePause

}

恢复动画:

func resumeAnimation(layer: CALayer) {

  let timePause = layer.timeOffset

  layer.speed = 1.0

  layer.timeOffset = 0.0

  layer.beginTime = 0.0

  let passTimeSincePause = layer.convertTime(CACurrentMediaTime(), nil) - timePause

  layer.beginTime = passTimeSincePause

}

相关文章

网友评论

      本文标题:iOS 暂停和恢复CoreAnimation层动画

      本文链接:https://www.haomeiwen.com/subject/feblcttx.html