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 {
|
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)
|
touchStartLocation = touch.location(in: self)
|
||||||
scrubbingStartFraction = fractionComplete
|
scrubbingStartFraction = fractionComplete
|
||||||
|
}
|
||||||
|
|
||||||
animator = UIViewPropertyAnimator(duration: 0.1, curve: .linear)
|
animator = UIViewPropertyAnimator(duration: 0.1, curve: .linear)
|
||||||
animator!.addAnimations {
|
animator!.addAnimations {
|
||||||
|
@ -290,13 +295,20 @@ private class VideoScrubbingControl: UIControl {
|
||||||
feedbackGenerator!.prepare()
|
feedbackGenerator!.prepare()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
updateScrubbing(for: touch)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
|
override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
|
||||||
|
updateScrubbing(for: touch)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateScrubbing(for touch: UITouch) {
|
||||||
guard let touchStartLocation,
|
guard let touchStartLocation,
|
||||||
let scrubbingStartFraction else {
|
let scrubbingStartFraction else {
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
let location = touch.location(in: self)
|
let location = touch.location(in: self)
|
||||||
let translation = CGPoint(x: location.x - touchStartLocation.x, y: location.y - touchStartLocation.y)
|
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))
|
transform = CGAffineTransform(scaleX: 1 + stretchAmount / bounds.width, y: 1 + 0.5 * (1 - stretchFactor))
|
||||||
.translatedBy(x: sign(unclampedFractionComplete) * stretchAmount / 2, y: 0)
|
.translatedBy(x: sign(unclampedFractionComplete) * stretchAmount / 2, y: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
|
override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
|
||||||
|
|
Loading…
Reference in New Issue