I am working with VoiceOver and an external keyboard. I need to detect when an user activates an element using keyboard or tap.
To achieve this, I have implemented:
public override func pressesEnded(_ presses: Set<UIPress>,
with event: UIPressesEvent?) {
guard let key = presses.first?.key else { return }
switch key.keyCode {
case .keyboardSpacebar:
addSelectedTraits()
default:
super.pressesEnded(presses, with: event)
}
}
The problem is that the space bar is not triggering this function as any other keys do. What could be the problem? Notice that I have activated the full access keyboard on my iPhone, this makes the space bar able to perform activation actions.