Improvement UI/UX in scrubbing

This commit is contained in:
PangMo5 2022-05-14 11:40:50 +09:00
parent 7a26e69685
commit 28c6f9e760
3 changed files with 28 additions and 9 deletions

View File

@ -74,9 +74,13 @@ final class VideoPlayerViewModel: ViewModel {
}
}
@Published
var isHiddenCenterViews = false
@Published
var sliderIsScrubbing: Bool = false {
didSet {
isHiddenCenterViews = sliderIsScrubbing
beganScrubbingCurrentSeconds = currentSeconds
}
}
@ -280,10 +284,10 @@ final class VideoPlayerViewModel: ViewModel {
leftLabelText = calculateTimeText(from: currentSeconds)
rightLabelText = calculateTimeText(from: secondsScrubbedRemaining)
scrubbingTimeLabelText = calculateTimeText(from: currentSeconds - beganScrubbingCurrentSeconds)
scrubbingTimeLabelText = calculateTimeText(from: currentSeconds - beganScrubbingCurrentSeconds, isScrubbing: true)
}
private func calculateTimeText(from duration: Double) -> String {
private func calculateTimeText(from duration: Double, isScrubbing: Bool = false) -> String {
let isNegative = duration < 0
let duration = abs(duration)
let hours = floor(duration / 3600)
@ -300,7 +304,11 @@ final class VideoPlayerViewModel: ViewModel {
"\(String(Int(floor(minutes))).leftPad(toWidth: 2, withString: "0")):\(String(Int(floor(seconds))).leftPad(toWidth: 2, withString: "0"))"
}
return "\(isNegative ? "-" : "") \(timeText)"
if isScrubbing {
return "\(isNegative ? "-" : "+") \(timeText)"
} else {
return "\(isNegative ? "-" : "") \(timeText)"
}
}
}

View File

@ -323,6 +323,7 @@ struct VLCPlayerOverlayView: View {
}
}
.font(.system(size: 48))
.opacity(viewModel.isHiddenCenterViews ? 0 : 1)
}
Spacer()

View File

@ -360,6 +360,7 @@ class VLCPlayerViewController: UIViewController {
private func didHorizontalPan(_ gestureRecognizer: UIPanGestureRecognizer) {
switch gestureRecognizer.state {
case .began:
exchangeOverlayView(isBringToFrontThanGestureView: false)
panBeganPoint = gestureRecognizer.location(in: mainGestureView)
panBeganSliderPercentage = viewModel.sliderPercentage
viewModel.sliderIsScrubbing = true
@ -370,8 +371,10 @@ class VLCPlayerViewController: UIViewController {
viewModel.sliderPercentage = min(max(0, panBeganSliderPercentage - changedValue), 1)
showSliderOverlay()
showOverlay()
default:
viewModel.sliderIsScrubbing = false
hideOverlay()
hideSystemControlOverlay()
}
}
@ -502,6 +505,17 @@ class VLCPlayerViewController: UIViewController {
currentJumpForwardOverlayView = newJumpForwardImageView
}
private var isOverlayViewBringToFrontThanGestureView = true
private func exchangeOverlayView(isBringToFrontThanGestureView: Bool) {
guard isBringToFrontThanGestureView != isOverlayViewBringToFrontThanGestureView,
let currentOverlayView = currentOverlayHostingController?.view,
let mainGestureViewIndex = view.subviews.firstIndex(of: mainGestureView),
let currentOVerlayViewIndex = view.subviews.firstIndex(of: currentOverlayView) else { return }
isOverlayViewBringToFrontThanGestureView = isBringToFrontThanGestureView
view.exchangeSubview(at: mainGestureViewIndex,
withSubviewAt: currentOVerlayViewIndex)
}
}
// MARK: setupMediaPlayer
@ -679,14 +693,12 @@ extension VLCPlayerViewController {
guard overlayHostingController.view.alpha != 0 else { return }
// for gestures UX
view.exchangeSubview(at: view.subviews.firstIndex(of: mainGestureView)!,
withSubviewAt: view.subviews.firstIndex(of: overlayHostingController.view)!)
exchangeOverlayView(isBringToFrontThanGestureView: false)
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut) {
overlayHostingController.view.alpha = 0
} completion: { [weak self] _ in
guard let self = self else { return }
self.view.exchangeSubview(at: self.view.subviews.firstIndex(of: self.mainGestureView)!,
withSubviewAt: self.view.subviews.firstIndex(of: overlayHostingController.view)!)
self.exchangeOverlayView(isBringToFrontThanGestureView: true)
self.viewModel.isHiddenOverlay = true
}
}
@ -773,8 +785,6 @@ extension VLCPlayerViewController {
}
private func showSliderOverlay() {
guard !displayingOverlay else { return }
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(systemName: "clock.arrow.circlepath",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 48))?