parent
a442197adf
commit
56d12295ba
|
@ -53,12 +53,35 @@ class GalleryDismissInteraction: NSObject {
|
|||
let translation = recognizer.translation(in: viewController.view)
|
||||
let velocity = recognizer.velocity(in: viewController.view)
|
||||
|
||||
let translationMagnitude = sqrt(translation.x.magnitudeSquared + translation.y.magnitudeSquared)
|
||||
let velocityMagnitude = sqrt(velocity.x.magnitudeSquared + velocity.y.magnitudeSquared)
|
||||
|
||||
if translationMagnitude < 150 && velocityMagnitude < 500 {
|
||||
isActive = false
|
||||
|
||||
let spring = UISpringTimingParameters(mass: 1, stiffness: 439, damping: 42, initialVelocity: .zero)
|
||||
let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring)
|
||||
animator.addAnimations {
|
||||
self.content!.view.frame = self.origContentFrameInGallery!
|
||||
self.viewController.currentItemViewController.setControlsVisible(self.origControlsVisible!, animated: false, dueToUserInteraction: false)
|
||||
}
|
||||
animator.addCompletion { _ in
|
||||
self.content!.view.removeFromSuperview()
|
||||
self.viewController.currentItemViewController.addContent()
|
||||
self.content = nil
|
||||
self.origContentFrameInGallery = nil
|
||||
self.origControlsVisible = nil
|
||||
}
|
||||
animator.startAnimation()
|
||||
|
||||
} else {
|
||||
dismissVelocity = velocity
|
||||
dismissTranslation = translation
|
||||
viewController.dismiss(animated: true)
|
||||
|
||||
// don't unset this until after dismiss is called, so that the dismiss animation controller can read it
|
||||
isActive = false
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue