因此,我已经能够使用tapGesture识别器成功覆盖菜单按钮的默认行为。我有类似的东西
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()
}
但似乎在转换和segue期间(如在一个视图控制器被替换/覆盖另一个视图控制器之间的动画中),如果按下它的菜单按钮似乎回退到默认情况下将视图控制器弹出堆栈。我觉得我已经尝试了一切,包括: