How to disable a UITextField keyboard without hiding it?

时光毁灭记忆、已成空白 提交于 2019-12-04 05:27:25

问题


I have an animation, during which I want to disable the keyboard but not hide it. I even tried self.view.userInteractionEnabled = NO;, but that hides the keyboard. I guess it must call resignFirstResponder.


回答1:


To disable everything, you can use

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

right before you start the animation and

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

after the animation finishes, e.g., in its completion block.




回答2:


You can disable the keyboard without dismissing it by doing:

NSArray *windows = [UIApplication sharedApplication].windows;
if ([windows count] > 1) {
    UIWindow *keyboardWindow = windows[1];
    keyboardWindow.userInteractionEnabled = NO;
}

But, it's obviously very hackish & fragile, and I'm not sure if it complies with Apple's terms.



来源:https://stackoverflow.com/questions/5915559/how-to-disable-a-uitextfield-keyboard-without-hiding-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!