Dismiss a UIKeyboardTypeNumberPad in a UITextField

2019-08-14 17:50发布

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条回答
Deceive 欺骗
2楼-- · 2019-08-14 18:11

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.

查看更多
登录 后发表回答