fix: workaround image preview may freeze issue
This commit is contained in:
parent
72a225bbc3
commit
504184e45b
|
@ -273,6 +273,10 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
||||||
transitionContext.containerView.addSubview(transitionMaskView)
|
transitionContext.containerView.addSubview(transitionMaskView)
|
||||||
transitionItem.interactiveTransitionMaskView = transitionMaskView
|
transitionItem.interactiveTransitionMaskView = transitionMaskView
|
||||||
|
|
||||||
|
let transitionMaskViewTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
|
||||||
|
transitionMaskViewTapGestureRecognizer.addTarget(self, action: #selector(MediaHostToMediaPreviewViewControllerAnimatedTransitioning.transitionMaskViewTapGestureRecognizerHandler(_:)))
|
||||||
|
transitionMaskView.addGestureRecognizer(transitionMaskViewTapGestureRecognizer)
|
||||||
|
|
||||||
let maskLayer = CAShapeLayer()
|
let maskLayer = CAShapeLayer()
|
||||||
maskLayer.frame = transitionMaskView.bounds
|
maskLayer.frame = transitionMaskView.bounds
|
||||||
maskLayer.path = UIBezierPath(rect: maskLayer.bounds).cgPath
|
maskLayer.path = UIBezierPath(rect: maskLayer.bounds).cgPath
|
||||||
|
@ -340,10 +344,32 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
|
// app may freeze without response during transitioning
|
||||||
|
// patch it by tap the view to finish transitioning
|
||||||
|
@objc func transitionMaskViewTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
||||||
|
// not panning now but still in transitioning
|
||||||
|
guard panGestureRecognizer.state == .possible,
|
||||||
|
transitionContext.isAnimated, transitionContext.isInteractive else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// finish or cancel current transitioning
|
||||||
|
let targetPosition = completionPosition()
|
||||||
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: target position: %s", ((#file as NSString).lastPathComponent), #line, #function, targetPosition == .end ? "end" : "start")
|
||||||
|
isTransitionContextFinish = true
|
||||||
|
animate(targetPosition)
|
||||||
|
|
||||||
|
targetPosition == .end ? transitionContext.finishInteractiveTransition() : transitionContext.cancelInteractiveTransition()
|
||||||
|
}
|
||||||
|
|
||||||
@objc func updatePanGestureInteractive(_ sender: UIPanGestureRecognizer) {
|
@objc func updatePanGestureInteractive(_ sender: UIPanGestureRecognizer) {
|
||||||
guard !isTransitionContextFinish else { return } // do not accept transition abort
|
guard !isTransitionContextFinish else {
|
||||||
|
return
|
||||||
|
} // do not accept transition abort
|
||||||
|
|
||||||
switch sender.state {
|
switch sender.state {
|
||||||
|
case .possible:
|
||||||
|
return
|
||||||
case .began, .changed:
|
case .began, .changed:
|
||||||
let translation = sender.translation(in: transitionContext.containerView)
|
let translation = sender.translation(in: transitionContext.containerView)
|
||||||
let percent = popInteractiveTransitionAnimator.fractionComplete + progressStep(for: translation)
|
let percent = popInteractiveTransitionAnimator.fractionComplete + progressStep(for: translation)
|
||||||
|
@ -360,7 +386,10 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
||||||
animate(targetPosition)
|
animate(targetPosition)
|
||||||
|
|
||||||
targetPosition == .end ? transitionContext.finishInteractiveTransition() : transitionContext.cancelInteractiveTransition()
|
targetPosition == .end ? transitionContext.finishInteractiveTransition() : transitionContext.cancelInteractiveTransition()
|
||||||
default:
|
case .failed:
|
||||||
|
return
|
||||||
|
@unknown default:
|
||||||
|
assertionFailure()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue