Remove toast on pan completion and avoid recenter exception (#592)

This commit is contained in:
Ryan Nystrom
2017-10-16 17:36:46 -04:00
committed by GitHub
parent 16a3e2375c
commit d51db6f3b9

View File

@@ -250,6 +250,7 @@ final class ToastManager {
}
func dismiss() {
invalidateTimer()
animator.removeBehavior(springBehavior)
UIView.animate(withDuration: 0.5, delay: 0, options: [.curveEaseInOut], animations: {
@@ -261,6 +262,9 @@ final class ToastManager {
}
func recenter() {
// UIDynamics will throw if adding the behavior back when the view has already been removed
guard view.superview != nil else { return }
animator.removeBehavior(springBehavior)
springBehavior.anchorPoint = anchor(view: view, viewController: viewController)
animator.addBehavior(springBehavior)
@@ -347,7 +351,9 @@ final class ToastManager {
var center = toast.view.center
center.y = finalY
toast.view.center = center
})
}) { _ in
toast.view.removeFromSuperview()
}
} else {
toast.startTimer()
toast.animator.addBehavior(toast.springBehavior)