Попробуйте это:
class FirstViewController: UIViewController {
@IBOutlet weak var menuConstraint: NSLayoutConstraint!
var sideMenuOpen = false
var gesture : UITapGestureRecognizer?
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(toggleSideMenu), name: NSNotification.Name("ToggleSideMenu"), object: nil)
gesture = UITapGestureRecognizer(target: self, action: #selector(FirstViewController.toggleSideMenu))
}
@objc func toggleSideMenu() {
if sideMenuOpen {
sideMenuOpen = false
menuConstraint.constant = -240
self.view.removeGestureRecognizer(gesture!)
} else {
sideMenuOpen = true
menuConstraint.constant = 0
self.view.addGestureRecognizer(gesture!)
}
}
}