forked from shadowfacts/Tusker
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 dismissVelocity: CGPoint?
|
||||||
private(set) var dismissTranslation: CGPoint?
|
private(set) var dismissTranslation: CGPoint?
|
||||||
|
|
||||||
|
private var cancelAnimator: UIViewPropertyAnimator?
|
||||||
|
|
||||||
init(viewController: GalleryViewController) {
|
init(viewController: GalleryViewController) {
|
||||||
self.viewController = viewController
|
self.viewController = viewController
|
||||||
super.init()
|
super.init()
|
||||||
|
@ -38,6 +40,8 @@ class GalleryDismissInteraction: NSObject {
|
||||||
content = viewController.currentItemViewController.takeContent()
|
content = viewController.currentItemViewController.takeContent()
|
||||||
content!.view.translatesAutoresizingMaskIntoConstraints = true
|
content!.view.translatesAutoresizingMaskIntoConstraints = true
|
||||||
content!.view.frame = origContentFrameInGallery!
|
content!.view.frame = origContentFrameInGallery!
|
||||||
|
// Make sure the context remains behind the controls
|
||||||
|
content!.view.layer.zPosition = -1000
|
||||||
viewController.view.addSubview(content!.view)
|
viewController.view.addSubview(content!.view)
|
||||||
|
|
||||||
origControlsVisible = viewController.currentItemViewController.controlsVisible
|
origControlsVisible = viewController.currentItemViewController.controlsVisible
|
||||||
|
@ -59,20 +63,27 @@ class GalleryDismissInteraction: NSObject {
|
||||||
if translationMagnitude < 150 && velocityMagnitude < 500 {
|
if translationMagnitude < 150 && velocityMagnitude < 500 {
|
||||||
isActive = false
|
isActive = false
|
||||||
|
|
||||||
|
cancelAnimator?.stopAnimation(true)
|
||||||
|
|
||||||
let spring = UISpringTimingParameters(mass: 1, stiffness: 439, damping: 42, initialVelocity: .zero)
|
let spring = UISpringTimingParameters(mass: 1, stiffness: 439, damping: 42, initialVelocity: .zero)
|
||||||
let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring)
|
cancelAnimator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring)
|
||||||
animator.addAnimations {
|
cancelAnimator!.addAnimations {
|
||||||
self.content!.view.frame = self.origContentFrameInGallery!
|
self.content!.view.frame = self.origContentFrameInGallery!
|
||||||
self.viewController.currentItemViewController.setControlsVisible(self.origControlsVisible!, animated: false, dueToUserInteraction: false)
|
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.content!.view.removeFromSuperview()
|
||||||
self.viewController.currentItemViewController.addContent()
|
self.viewController.currentItemViewController.addContent()
|
||||||
self.content = nil
|
self.content = nil
|
||||||
self.origContentFrameInGallery = nil
|
self.origContentFrameInGallery = nil
|
||||||
self.origControlsVisible = nil
|
self.origControlsVisible = nil
|
||||||
}
|
}
|
||||||
animator.startAnimation()
|
cancelAnimator!.startAnimation()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dismissVelocity = velocity
|
dismissVelocity = velocity
|
||||||
|
|
Loading…
Reference in New Issue