It's possible to pause and resume CAAnimations, but it's fussy and a little confusing. Take a look at this project on Github:
https://github.com/DuncanMC/ClockWipeSwift.git
It uses an extension on CALayer:
// Credit to Rand, from Stack Overflow, for the basis of this extension
// see https://stackoverflow.com/a/59079995/205185
import UIKit
import CoreGraphics
import Foundation
extension CALayer
{
func isPaused() -> Bool {
return speed == 0
}
private func internalPause(_ pause: Bool) {
if pause {
let pausedTime = convertTime(CACurrentMediaTime(), from: nil)
speed = 0.0
timeOffset = pausedTime
} else {
let pausedTime = timeOffset
speed = 1.0
timeOffset = 0.0
beginTime = 0.0
let timeSincePause = convertTime(CACurrentMediaTime(), from: nil) - pausedTime
beginTime = timeSincePause
}
}
func pauseAnimation(_ pause: Bool) {
if pause != isPaused() {
internalPause(pause)
}
}
func pauseOrResumeAnimation() {
internalPause(isPaused())
}
}
Pausing and resuming is much easier if you use UIView animation and UIViewPropertyAnimator. There are lots of tutorials that explain how to do it.
You can look at this project on Github that shows how to use UIViewPropertyAnimator
.