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
private lazy var gestureRecognizer: UIPanGestureRecognizer = { | |
let recognizer = UIPanGestureRecognizer(target: self, action: #selector(updateProgress(_:))) | |
recognizer.maximumNumberOfTouches = 1 | |
return recognizer | |
}() | |
@objc private func updateProgress(_ recognizer: UIPanGestureRecognizer) { | |
if animator == nil { | |
animator = makeAnimator() | |
} | |
guard let animator = animator else { return } | |
switch recognizer.state { | |
case .began: | |
animator.pauseAnimation() | |
fractionCompletedStart = animator.fractionComplete | |
dragStartPosition = recognizer.location(in: view) | |
case .changed: | |
animator.pauseAnimation() | |
let delta = recognizer.location(in: view).x - dragStartPosition.x | |
animator.fractionComplete = max(0.0, min(1.0, fractionCompletedStart + delta / 300.0)) | |
case .ended: | |
animator.startAnimation() | |
default: | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment