So I've been able to successfully override the menu button's default behavior using a tapGesture recognizer. I have something like this
func addMenuButtonLock() {
defaultMenuTapRecognizer = UITapGestureRecognizer(target: self, action: Selector())
defaultMenuTapRecognizer!.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(defaultMenuTapRecognizer!)
}
func removeMenuButtonLock() {
if defaultMenuTapRecognizer != nil {
self.view.removeGestureRecognizer(defaultMenuTapRecognizer!)
defaultMenuTapRecognizer = nil
}
}
override func viewWillAppear(animated: Bool) {
addMenuButtonLock()
super.viewWillAppear(animated)
}
override func viewDidAppear(animated: Bool) {
removeMenuButtonLock()
super.viewDidAppear(animated)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
addMenuLock()
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
removeMenuLock()
}
But it seems like during transitions and segues (as in the animation between one view controller being replaced/covered with another), if the menu button in pressed it seems to fallback to the default of popping the view controller off the stack. I feel like I've tried everything, including:
- Not removing the tapgesturerecognizer at all
- Calling them before calling the super methods for the view appearance functions
- Adding a tapgesturerecognizer to the underlying navigation controller (subclassing it)
- Overriding pressesBegan, pressesCancelled and pressesEnded. In this case, it captures the menu press, but despite me never calling their super method, the view is still popped. I'm seriously lost.