Precise video scrubbing for pointer/pencil
This commit is contained in:
parent
d1af911241
commit
9fefc9e8f8
|
@ -270,8 +270,13 @@ private class VideoScrubbingControl: UIControl {
|
|||
}
|
||||
|
||||
override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
|
||||
if touch.type == .pencil || touch.type == .indirectPointer {
|
||||
touchStartLocation = .zero
|
||||
scrubbingStartFraction = 0
|
||||
} else {
|
||||
touchStartLocation = touch.location(in: self)
|
||||
scrubbingStartFraction = fractionComplete
|
||||
}
|
||||
|
||||
animator = UIViewPropertyAnimator(duration: 0.1, curve: .linear)
|
||||
animator!.addAnimations {
|
||||
|
@ -290,13 +295,20 @@ private class VideoScrubbingControl: UIControl {
|
|||
feedbackGenerator!.prepare()
|
||||
#endif
|
||||
|
||||
updateScrubbing(for: touch)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
|
||||
updateScrubbing(for: touch)
|
||||
return true
|
||||
}
|
||||
|
||||
private func updateScrubbing(for touch: UITouch) {
|
||||
guard let touchStartLocation,
|
||||
let scrubbingStartFraction else {
|
||||
return false
|
||||
return
|
||||
}
|
||||
let location = touch.location(in: self)
|
||||
let translation = CGPoint(x: location.x - touchStartLocation.x, y: location.y - touchStartLocation.y)
|
||||
|
@ -326,8 +338,6 @@ private class VideoScrubbingControl: UIControl {
|
|||
transform = CGAffineTransform(scaleX: 1 + stretchAmount / bounds.width, y: 1 + 0.5 * (1 - stretchFactor))
|
||||
.translatedBy(x: sign(unclampedFractionComplete) * stretchAmount / 2, y: 0)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
|
||||
|
|
Loading…
Reference in New Issue