How to present Context Menu alongside software keyboard?

Is it possible to present a Context Menu alongside software keyboard?

I'm trying to present context menu via tapping a button while locking focus on a UITextField in the meantime. But found out whenever the context menu is presented, keyboard is automatically dismissed. Even strangely, canResignFirstResponder() and resignFirstResponder() are not called at all.

Sample code:
Code Block swift
class TextField: UITextField {
    override var canResignFirstResponder: Bool {
        print(#function)
        return false
    }
    override func resignFirstResponder() -> Bool {
        print(#function)
        return false
    }
}
class ViewController: UIViewController {
    @IBOutlet var textField: UITextField!
    @IBOutlet var button: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        button.menu = UIMenu(title: "", children: [
            UIAction(title: "Hello") { _ in }
        ])
        button.showsMenuAsPrimaryAction = true
    }
    override var disablesAutomaticKeyboardDismissal: Bool {
        print(#function)
        return true
    }
}


Presenting a menu in contexts where that menu isn't in the keyboard itself (e.g. the keyboard assistant bar) will dismiss the keyboard while the menu is up. First responder is not actually changed during that time, simply suppressed, which is why you don't see resignFirstResponder called.
How to present Context Menu alongside software keyboard?
 
 
Q