Created
April 27, 2019 13:32
-
-
Save laevandus/5c871f29c7f192e9d7c1c192bbc8d721 to your computer and use it in GitHub Desktop.
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