mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 00:22:12 +00:00
fixed pan crashes
This commit is contained in:
parent
7dd3609078
commit
db4d74252d
1 changed files with 0 additions and 82 deletions
|
|
@ -1015,7 +1015,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
skipIntroButton.layer.masksToBounds = false
|
skipIntroButton.layer.masksToBounds = false
|
||||||
|
|
||||||
skipIntroButton.addTarget(self, action: #selector(skipIntro), for: .touchUpInside)
|
skipIntroButton.addTarget(self, action: #selector(skipIntro), for: .touchUpInside)
|
||||||
skipIntroButton.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleIntroPan(_:))))
|
|
||||||
|
|
||||||
view.addSubview(skipIntroButton)
|
view.addSubview(skipIntroButton)
|
||||||
skipIntroButton.translatesAutoresizingMaskIntoConstraints = false
|
skipIntroButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
@ -1047,7 +1046,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
skipOutroButton.layer.masksToBounds = false
|
skipOutroButton.layer.masksToBounds = false
|
||||||
|
|
||||||
skipOutroButton.addTarget(self, action: #selector(skipOutro), for: .touchUpInside)
|
skipOutroButton.addTarget(self, action: #selector(skipOutro), for: .touchUpInside)
|
||||||
skipOutroButton.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleOutroPan(_:))))
|
|
||||||
|
|
||||||
view.addSubview(skipOutroButton)
|
view.addSubview(skipOutroButton)
|
||||||
skipOutroButton.translatesAutoresizingMaskIntoConstraints = false
|
skipOutroButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
@ -1425,87 +1423,9 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func handleIntroPan(_ g: UIPanGestureRecognizer) {
|
|
||||||
let translation = g.translation(in: view).x
|
|
||||||
switch g.state {
|
|
||||||
case .began:
|
|
||||||
originalIntroLeading = skipIntroLeading.constant
|
|
||||||
case .changed:
|
|
||||||
skipIntroLeading.constant = originalIntroLeading + min(0, translation)
|
|
||||||
view.layoutIfNeeded()
|
|
||||||
case .ended, .cancelled:
|
|
||||||
let threshold = -skipIntroButton.bounds.width * 0.4
|
|
||||||
if skipIntroLeading.constant < originalIntroLeading + threshold {
|
|
||||||
// animate all the way off to the left
|
|
||||||
let offscreen = -skipIntroButton.bounds.width - 100
|
|
||||||
UIView.animate(
|
|
||||||
withDuration: 0.25,
|
|
||||||
animations: {
|
|
||||||
self.skipIntroLeading.constant = offscreen
|
|
||||||
self.view.layoutIfNeeded()
|
|
||||||
}, completion: { _ in
|
|
||||||
self.skipIntroDismissedInSession = true
|
|
||||||
self.skipIntroButton.isHidden = true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// bounce back
|
|
||||||
UIView.animate(
|
|
||||||
withDuration: 0.3,
|
|
||||||
delay: 0,
|
|
||||||
usingSpringWithDamping: 0.6,
|
|
||||||
initialSpringVelocity: 1,
|
|
||||||
options: [],
|
|
||||||
animations: {
|
|
||||||
self.skipIntroLeading.constant = self.originalIntroLeading
|
|
||||||
self.view.layoutIfNeeded()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
default: break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func handleOutroPan(_ g: UIPanGestureRecognizer) {
|
|
||||||
let translation = g.translation(in: view).x
|
|
||||||
switch g.state {
|
|
||||||
case .began:
|
|
||||||
originalOutroLeading = skipOutroLeading.constant
|
|
||||||
case .changed:
|
|
||||||
skipOutroLeading.constant = originalOutroLeading + min(0, translation)
|
|
||||||
view.layoutIfNeeded()
|
|
||||||
case .ended, .cancelled:
|
|
||||||
let threshold = -skipOutroButton.bounds.width * 0.4
|
|
||||||
if skipOutroLeading.constant < originalOutroLeading + threshold {
|
|
||||||
// animate off to the left
|
|
||||||
let offscreen = -skipOutroButton.bounds.width - 100
|
|
||||||
UIView.animate(
|
|
||||||
withDuration: 0.25,
|
|
||||||
animations: {
|
|
||||||
self.skipOutroLeading.constant = offscreen
|
|
||||||
self.view.layoutIfNeeded()
|
|
||||||
}, completion: { _ in
|
|
||||||
self.skipOutroDismissedInSession = true
|
|
||||||
self.skipOutroButton.isHidden = true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
UIView.animate(
|
|
||||||
withDuration: 0.3,
|
|
||||||
delay: 0,
|
|
||||||
usingSpringWithDamping: 0.6,
|
|
||||||
initialSpringVelocity: 1,
|
|
||||||
options: [],
|
|
||||||
animations: {
|
|
||||||
self.skipOutroLeading.constant = self.originalOutroLeading
|
|
||||||
self.view.layoutIfNeeded()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
default: break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func skipIntro() {
|
@objc private func skipIntro() {
|
||||||
if let range = skipIntervals.op {
|
if let range = skipIntervals.op {
|
||||||
player.seek(to: range.end)
|
player.seek(to: range.end)
|
||||||
// optionally hide button immediately:
|
|
||||||
skipIntroButton.isHidden = true
|
skipIntroButton.isHidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1526,10 +1446,8 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateMenuButtonConstraints() {
|
func updateMenuButtonConstraints() {
|
||||||
// tear down last one
|
|
||||||
currentMenuButtonTrailing.isActive = false
|
currentMenuButtonTrailing.isActive = false
|
||||||
|
|
||||||
// pick the “next” visible control
|
|
||||||
let anchor: NSLayoutXAxisAnchor
|
let anchor: NSLayoutXAxisAnchor
|
||||||
if !qualityButton.isHidden {
|
if !qualityButton.isHidden {
|
||||||
anchor = qualityButton.leadingAnchor
|
anchor = qualityButton.leadingAnchor
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue