如何以编程方式检查iOS应用程序中是否存在键盘?
问题描述:
我需要检查iOS应用中键盘可见性的状况。
I need to check the condition of keyboard visibility in my iOS app.
Pseudocode:
Pseudocode:
if(keyboardIsPresentOnWindow) {
//Do action 1
}
else if (keyboardIsNotPresentOnWindow) {
//Do action 2
}
如何检查这种情况?
答
...或采取简单的方法:
…or take the easy way:
当您输入textField时,它将成为第一响应者然后出现键盘。
您可以使用 [myTextField isFirstResponder]
检查键盘的状态。如果它返回 YES
,则键盘处于活动状态。
When you enter a textField, it becomes first responder and the keyboard appears.
You can check the status of the keyboard with [myTextField isFirstResponder]
. If it returns YES
, then the the keyboard is active.