From fe6ed9f5781a2e30092f78e769d210487175bd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= Date: Thu, 28 Dec 2017 13:17:14 +0300 Subject: [PATCH] add bounces property --- Source/BTNavigationDropdownMenu.swift | 25 ++++++++++++++++++++++--- Source/Internal/BTConfiguration.swift | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Source/BTNavigationDropdownMenu.swift b/Source/BTNavigationDropdownMenu.swift index a1791e82..f53a5383 100755 --- a/Source/BTNavigationDropdownMenu.swift +++ b/Source/BTNavigationDropdownMenu.swift @@ -29,6 +29,15 @@ import UIKit // MARK: BTNavigationDropdownMenu open class BTNavigationDropdownMenu: UIView { + open var bounces: Bool { + get { + return self.configuration.bounces + } + set(value) { + self.configuration.bounces = value + } + } + // The color of menu title. Default is darkGrayColor() open var menuTitleColor: UIColor! { get { @@ -460,11 +469,21 @@ open class BTNavigationDropdownMenu: UIView { self.menuWrapper.superview?.bringSubview(toFront: self.menuWrapper) + var animationDuration: Double = self.configuration.animationDuration + var damping: CGFloat = 1.0 + var velocity: CGFloat = 1.0 + + if self.bounces { + animationDuration *= 1.5 + damping = 0.7 + velocity = 0.5 + } + UIView.animate( - withDuration: self.configuration.animationDuration * 1.5, + withDuration: animationDuration, delay: 0, - usingSpringWithDamping: 0.7, - initialSpringVelocity: 0.5, + usingSpringWithDamping: damping, + initialSpringVelocity: velocity, options: [], animations: { self.tableView.frame.origin.y = CGFloat(-300) diff --git a/Source/Internal/BTConfiguration.swift b/Source/Internal/BTConfiguration.swift index f25c5eb8..21045650 100644 --- a/Source/Internal/BTConfiguration.swift +++ b/Source/Internal/BTConfiguration.swift @@ -24,6 +24,7 @@ import UIKit final class BTConfiguration { + var bounces: Bool! var menuTitleColor: UIColor? var cellHeight: CGFloat! var cellBackgroundColor: UIColor? @@ -57,6 +58,7 @@ final class BTConfiguration { let arrowImagePath = imageBundle?.path(forResource: "arrow_down_icon", ofType: "png") // Default values + self.bounces = true self.menuTitleColor = UIColor.darkGray self.cellHeight = 50 self.cellBackgroundColor = UIColor.white