title: How to reuse slide up menu class in any view controller?
body: <p>I am trying to create a slide up menu, completely defined in a custom class named OldMenu.</p>
  <p>It would show every time a user tap a UIBarButtonItem, that is also defined in that class.</p>
  <p>So the button, the menu, and the menu animation to show the menu are all defined in this custom class.</p>
  <p>For now, I can just access the button from an other class but it doesn't seem to trigger the animation to show the menu.</p>
  <p>Any one knows why this code isn't working?</p>
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          let oldMenu = OldMenu()
          navigationItem.rightBarButtonItems = [oldMenu.MenuButton]
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  }
  
  class OldMenu: NSObject, UITableViewDelegate, UITableViewDataSource {
      var tableView: UITableView {
          let tableView = UITableView()
          tableView.isScrollEnabled = true
          tableView.delegate = self
          tableView.dataSource = self
          tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: &quot;Cell&quot;)
          return tableView
      }
      
      var transparentView = UIView()
      
      let height: CGFloat = 250
      
      var MenuButton: UIBarButtonItem {
          let btn = UIBarButtonItem()
          btn.title = &quot;Menu&quot;
          btn.target = self
          btn.action = #selector(onClickMenu)
          return btn
      }
  }
  
  extension OldMenu {
      
      @objc func onClickMenu(_ sender: Any) {
          let window = UIApplication.shared.keyWindow
          transparentView.backgroundColor = UIColor.black.withAlphaComponent(0.9)
          transparentView.frame = window?.bounds ?? .zero
          window?.addSubview(transparentView)
          
          let screenSize = UIScreen.main.bounds.size
          tableView.frame = CGRect(x: 0, y: screenSize.height, width: screenSize.width, height: height)
          window?.addSubview(tableView)
          
          let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onClickTransparentView))
          transparentView.addGestureRecognizer(tapGesture)
          
          transparentView.alpha = 0
          
          UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
              self.transparentView.alpha = 0.5
              self.tableView.frame = CGRect(x: 0, y: screenSize.height - self.height, width: screenSize.width, height: self.height)
          }, completion: nil)
          
      }
      
      @objc func onClickTransparentView() {
          let screenSize = UIScreen.main.bounds.size
  
          UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
              self.transparentView.alpha = 0
              self.tableView.frame = CGRect(x: 0, y: screenSize.height, width: screenSize.width, height: self.height)
          }, completion: nil)
      }
  }
  
  extension OldMenu {
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return 5
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          return UITableViewCell()
      }
      
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return 50
      }
      
  }
  </code></pre>