Skip to content

Instantly share code, notes, and snippets.

@mhijack
Created April 27, 2021 23:07
Show Gist options
  • Save mhijack/7e50c2296bc0c7c830f7979313dfc85d to your computer and use it in GitHub Desktop.
Save mhijack/7e50c2296bc0c7c830f7979313dfc85d to your computer and use it in GitHub Desktop.
import Stevia
class OverflowLauncher: NSObject {
var backgroundView: UIView?
var menuView: UIView?
func testAddView() {
guard let window = UIApplication.shared.windows.first else { return }
let backgroundView = UIView(frame: window.bounds)
self.backgroundView = backgroundView
backgroundView.backgroundColor = .black
backgroundView.alpha = 0
window.sv(backgroundView)
backgroundView.fillContainer()
let menu = UIView()
self.menuView = menu
backgroundView.sv(menu)
menu.height(205).leading(0).trailing(0)
menu.Width == backgroundView.Width
menu.Bottom == backgroundView.Bottom + 205
menu.backgroundColor = .white
menu.alpha = 1
let tap = UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
backgroundView.isUserInteractionEnabled = true
backgroundView.addGestureRecognizer(tap)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
menu.bottomConstraint?.constant = 5
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, animations: {
backgroundView.alpha = 0.5
backgroundView.layoutIfNeeded()
}) { (complete) in
}
}
}
@objc private func didTapBackground() {
dismiss()
}
private func dismiss() {
self.menuView?.bottomConstraint?.constant = 205
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, animations: {
self.backgroundView?.alpha = 0
self.backgroundView?.layoutIfNeeded()
}) { (complete) in
self.backgroundView?.removeFromSuperview()
self.backgroundView = nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment