用户登录
用户注册

分享至

UITextField 没有得到键盘输入

  • 作者: 陆太师
  • 来源: 51数据库
  • 2023-02-09

问题描述

我在 SVProgressHUD 下的 UITextField 中输入文本时遇到问题(基本上是一个完整的 UIView-screen 透明 UIWindow 和一些 UIView 子视图显示文本和自定义绘制的进度条).

I'm having troubles entering text into an UITextField under a SVProgressHUD (Basically an UIView with a full-screen transparent UIWindow and some UIView subviews showing text and a custom-drawn progress bar).

我的问题是 UITextField 显示闪烁的光标并且键盘显示,但是当我点击一个键时,文本字段中没有输入任何内容.我只看到光标的闪烁中断就像平常一样.有趣的是,后退(删除)键有效(它确实删除了 UITextView 中的最后一个字母),但没有任何其他键.

My problem is that the UITextField displays the blinking cursor and the keyboard shows, but when I tap a key, nothing is entered into the text field. I only see that the cursor's blinking interrupts just like normal. Interestingly enough, the back (delete) key works (it really deletes the last letter in the UITextView), but not any other key.

我使用的是 iOS 6.

I'm using iOS 6.

任何帮助将不胜感激.

当没有显示 SVProgressHUD 时,相同的 UITextField 可以正常工作.这让我觉得它与第一响应者有关,但我已经尝试在 SVProgressHUD 的每个窗口和子视图上调用 resignFirstResponder ,但它仍然不起作用.

The same UITextField works fine when there's no SVProgressHUD displayed. This makes me think it has something to do with the first responder, but I have already tried calling resignFirstResponder on every window and subview of the SVProgressHUD and it still does not work.

推荐答案

终于找到问题了:SVProgressHUD 在初始化时调用 makeKeyAndVisible,因为它想要接收键盘通知以进行重新定位.我查了一下关键窗口"实际上是什么,发现:

I finally found the problem: SVProgressHUD calls makeKeyAndVisible when it's initialized, because it wants to receive keyboard notifications for repositioning. I looked up what the "Key Window" actually is and found out:

...按键窗口响应用户输入...

...The key window responds to user input...

现在,由于 SVProgressHUD 的 UIWindow 是 keyWindow,我的另一个包含 UITextField 的窗口没有得到用户输入.

Now, as the UIWindow of the SVProgressHUD was the keyWindow, my other window, which contained the UITextField did not get the user input.

我终于在 AppDelegate 的窗口上调用了 makeKeyWindow,一切正常.

I finally call makeKeyWindow on the AppDelegate's window and everything is working fine.

我希望这可以帮助任何有类似问题的人.

I hope this helps anyone with similar problems.

软件
前端设计
程序设计
Java相关