Helper methods to control CALayer i.e Interactive transitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension CALayer { | |
func pause() -> TimeInterval { | |
if #available(iOS 11, *) { | |
let pausedTime = convertTime(CACurrentMediaTime(), from: nil) | |
speed = 0 | |
timeOffset = pausedTime | |
return pausedTime | |
} | |
speed = 0 | |
return timeOffset | |
} | |
func resume(from pauseTime: TimeInterval? = nil) { | |
let pausedTime = pauseTime ?? timeOffset | |
speed = 1 | |
timeOffset = 0 | |
beginTime = 0 | |
let timeSincePause = convertTime(CACurrentMediaTime(), from: nil) - pausedTime | |
beginTime = timeSincePause | |
} | |
func rewind(finishTime: Double) { | |
speed = -1 | |
if #available(iOS 11, *) { | |
beginTime = CACurrentMediaTime() | |
DispatchQueue.main.asyncAfter(deadline: .now() + finishTime) { | |
self.speed = 1 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment