Gallery dismiss interaction fixes
This commit is contained in:
parent
56d12295ba
commit
fa828a5eae
|
@ -20,6 +20,8 @@ class GalleryDismissInteraction: NSObject {
|
|||
private(set) var dismissVelocity: CGPoint?
|
||||
private(set) var dismissTranslation: CGPoint?
|
||||
|
||||
private var cancelAnimator: UIViewPropertyAnimator?
|
||||
|
||||
init(viewController: GalleryViewController) {
|
||||
self.viewController = viewController
|
||||
super.init()
|
||||
|
@ -38,6 +40,8 @@ class GalleryDismissInteraction: NSObject {
|
|||
content = viewController.currentItemViewController.takeContent()
|
||||
content!.view.translatesAutoresizingMaskIntoConstraints = true
|
||||
content!.view.frame = origContentFrameInGallery!
|
||||
// Make sure the context remains behind the controls
|
||||
content!.view.layer.zPosition = -1000
|
||||
viewController.view.addSubview(content!.view)
|
||||
|
||||
origControlsVisible = viewController.currentItemViewController.controlsVisible
|
||||
|
@ -59,20 +63,27 @@ class GalleryDismissInteraction: NSObject {
|
|||
if translationMagnitude < 150 && velocityMagnitude < 500 {
|
||||
isActive = false
|
||||
|
||||
cancelAnimator?.stopAnimation(true)
|
||||
|
||||
let spring = UISpringTimingParameters(mass: 1, stiffness: 439, damping: 42, initialVelocity: .zero)
|
||||
let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring)
|
||||
animator.addAnimations {
|
||||
cancelAnimator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring)
|
||||
cancelAnimator!.addAnimations {
|
||||
self.content!.view.frame = self.origContentFrameInGallery!
|
||||
self.viewController.currentItemViewController.setControlsVisible(self.origControlsVisible!, animated: false, dueToUserInteraction: false)
|
||||
}
|
||||
animator.addCompletion { _ in
|
||||
cancelAnimator!.addCompletion { _ in
|
||||
guard !self.isActive else {
|
||||
// bail in case the animation finishing raced with the user's interaction
|
||||
return
|
||||
}
|
||||
self.content!.view.layer.zPosition = 0
|
||||
self.content!.view.removeFromSuperview()
|
||||
self.viewController.currentItemViewController.addContent()
|
||||
self.content = nil
|
||||
self.origContentFrameInGallery = nil
|
||||
self.origControlsVisible = nil
|
||||
}
|
||||
animator.startAnimation()
|
||||
cancelAnimator!.startAnimation()
|
||||
|
||||
} else {
|
||||
dismissVelocity = velocity
|
||||
|
|
Loading…
Reference in New Issue