Skip to content

Instantly share code, notes, and snippets.

@aybekckaya
Last active May 13, 2020 23:01
Show Gist options
  • Save aybekckaya/2d650d86590f5f764a974bce3e97bd41 to your computer and use it in GitHub Desktop.
Save aybekckaya/2d650d86590f5f764a974bce3e97bd41 to your computer and use it in GitHub Desktop.
// MARK: Interactive Menu {Class}
class InteractiveMenu: UIView {
fileprivate let containerViewBottomMarginRate:CGFloat = 0.5 // 1
fileprivate let dampingValue:CGFloat = 1.5 // 2a
fileprivate let responseValue:CGFloat = 5.5 // 2b
fileprivate let viewBlurBackground:UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.translatesAutoresizingMaskIntoConstraints = true
blurView.alpha = 0.8
return blurView
}()
fileprivate let containerView:UIView = {
let view = UIView(frame: CGRect.zero)
view.translatesAutoresizingMaskIntoConstraints = true
view.backgroundColor = #colorLiteral(red: 0.06666666667, green: 0.07058823529, blue: 0.07450980392, alpha: 1)
view.layer.cornerRadius = 16
view.layer.masksToBounds = true
return view
}()
fileprivate var configuration:InteractiveMenuConfiguration = InteractiveMenuConfiguration() // 3
fileprivate var dataSource:InteractiveMenuDataSource!
fileprivate var delegate:InteractiveMenuDelegate?
fileprivate var frameClosedPosition:CGRect = CGRect.zero //4a
fileprivate var frameOpenPosition:CGRect = CGRect.zero // 4b
fileprivate var animator:UIViewPropertyAnimator = UIViewPropertyAnimator() // 5
fileprivate var viewInContainer:UIView!
fileprivate var scrollableContentView:UIScrollView? // 6
fileprivate var panGestureContainerView:UIPanGestureRecognizer!
fileprivate var panGestureScrollableContent:UIPanGestureRecognizer?
fileprivate var totalHeightContainerView:CGFloat {
return self.configuration.containerViewHeight + self.configuration.containerViewHeight * self.containerViewBottomMarginRate
}
init(embedIn view:UIView , dataSource : InteractiveMenuDataSource , delegate:InteractiveMenuDelegate? , configuration:InteractiveMenuConfiguration) {
super.init(frame: CGRect.zero)
self.dataSource = dataSource
self.configuration = configuration
self.delegate = delegate
view.addSubview(self)
self.setUpUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment