如何解决Swift如何播放和暂停UIBezier动画
我正在一个项目中,我使用圆形的UIBezier动画显示倒数计时器。我有一个播放和暂停按钮,可以开始和停止对时间的跟踪,但是动画还在继续。
如何暂停和恢复动画?这是我正在使用的代码段:
func drawCircleAnimation(minutes : Double) {
let padding = CGFloat(220)
let height = minuteLabel.frame.height + padding
let circularPath = UIBezierPath(arcCenter: minuteLabel.layer.position,radius: (height/2),startAngle: -.pi / 2,endAngle: 2 * .pi,clockwise: true)
progressLayer.path = circularPath.cgPath
progressLayer.fillColor = UIColor.clear.cgColor
progressLayer.strokeColor = UIColor(named: K.BrandColors.orange)?.cgColor
progressLayer.lineCap = .round
progressLayer.lineWidth = 10.0
progressLayer.strokeEnd = 0
mainContent.layer.addSublayer(progressLayer)
progressAnimation.toValue = 1
progressAnimation.duration = (minutes * 60)
progressAnimation.fillMode = .forwards
progressAnimation.isRemovedOnCompletion = true
progressLayer.add(progressAnimation,forKey: "progressAnim")
}
@IBAction func playPauseButton(_ sender: UIButton) {
exerciseSwitchStack.distribution = .fillEqually
sender.setTitle("",for: UIControl.State.normal)
if isTimeRunning == false {
startTimer()
resumeAnimation()
drawCircleAnimation(minutes: Double(workout?.exerciseArr[counter].minuteNum ?? 0))
sender.setImage(UIImage(named: "pause"),for: UIControl.State.normal)
}
else {
pauseTimer()
pauseAnimation(minutes: 2)
sender.setImage(UIImage(named: "play"),for: UIControl.State.normal)
}
}
@IBAction func playPauseButton(_ sender: UIButton) {
exerciseSwitchStack.distribution = .fillEqually
sender.setTitle("",for: UIControl.State.normal)
}
}
非常感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。