From 9b19249cc0b37f9d4d13d7949470404293a8ceb0 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Mon, 25 May 2020 16:05:07 +0300 Subject: [PATCH] [iOS] Added pan gesture to bottom menu --- .../Menu/BottomMenuViewController.swift | 30 +++++++++++++++++-- .../Menu/BottomMenuViewController.xib | 21 +++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift b/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift index d0fb437f00..e381e9cabb 100644 --- a/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift +++ b/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift @@ -8,7 +8,8 @@ class BottomMenuViewController: MWMViewController { @IBOutlet var tableView: UITableView! @IBOutlet var heightConstraint: NSLayoutConstraint! - + @IBOutlet var bottomConstraint: NSLayoutConstraint! + lazy var chromeView: UIView = { let view = UIView() view.styleName = "BlackStatusBarBackground" @@ -47,7 +48,32 @@ class BottomMenuViewController: MWMViewController { @IBAction func onClosePressed(_ sender: Any) { presenter?.onClosePressed() } - + + @IBAction func onPan(_ sender: UIPanGestureRecognizer) { + let yOffset = sender.translation(in: view.superview).y + let yVelocity = sender.velocity(in: view.superview).y + sender.setTranslation(CGPoint.zero, in: view.superview) + bottomConstraint.constant = min(bottomConstraint.constant - yOffset, 0); + + let alpha = 1.0 - abs(bottomConstraint.constant / tableView.height) + self.chromeView.alpha = alpha + + let state = sender.state + if state == .ended || state == .cancelled { + if yVelocity > 0 || (yVelocity == 0 && alpha < 0.8) { + presenter?.onClosePressed() + } else { + let duration = min(kDefaultAnimationDuration, TimeInterval(self.bottomConstraint.constant / yVelocity)) + self.view.layoutIfNeeded() + UIView.animate(withDuration: duration) { + self.chromeView.alpha = 1 + self.bottomConstraint.constant = 0 + self.view.layoutIfNeeded() + } + } + } + } + override var transitioningDelegate: UIViewControllerTransitioningDelegate? { get { return transitioningManager } set { } diff --git a/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.xib b/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.xib index 172ff93840..f6d20e0276 100644 --- a/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.xib +++ b/iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.xib @@ -10,6 +10,7 @@ + @@ -45,7 +46,7 @@ - + @@ -56,7 +57,9 @@ - + + + @@ -64,10 +67,8 @@ - - + - @@ -75,12 +76,20 @@ + + + - + + + + + +