问题
How do I dismiss a UITextField
with keyboard type UIKeyboardTypeNumberPad
? The accepted answer to this question suggests to either add a bar with a dismiss button as an inputAccessoryView
or to listen to touch events on the background.
I prefer the second approach, i.e. listen to touch events on the view containing the UITextField
. However, this approach fails if VoiceOver is active. How do you resignFirstResponder
in that situation?
回答1:
You need an alternative way to perform the gesture. You'll have to add a button to your layout. Sorry...
You should be able to check whether VoiceOver is on or not.
BOOL UIAccessibilityIsVoiceOverRunning();
You could also consider adding a tap recognizer to an invisible UI Element or a parent View that is completely covered with other elements. In this way, it would only be able to be activated by a VoiceOver user.
来源:https://stackoverflow.com/questions/30872419/dismiss-a-uikeyboardtypenumberpad-in-a-uitextfield-when-voiceover-is-active