iPhone - UIView 与键盘一起呈现 - 可以工作,但有错误
我有一个 UIViewController,它有两个文本字段:inputA
和 inputB
。 inputA
的工作方式与普通文本字段类似,单击它,键盘就会显示出来,您就可以输入内容。但是 inputB
触发另一个视图(将其视为一个按钮)。第二个视图 MyView
有一个自定义弹出视图,该视图通过键盘进行动画显示。 MyView
的弹出窗口最初的 alpha 为 0,我已经设置了键盘显示时的通知,将弹出窗口的视图 alpha 设置为 1。
这很好用,但我有一个“ bug”,当键盘当前显示时,因为用户先点击 inputA,然后点击 inputB,它会触发 MyView,但因为键盘已经显示,所以不会发送通知来更改弹出窗口的 alpha 1.
那么问题是:解决这个问题的干净方法是什么?我希望视图与键盘一起出现,但如果它已经存在,则应该将其发送。
有没有办法测试键盘是否已经显示? 我想这样做,而不是每次键盘在这两个视图中显示/隐藏时都设置布尔值。
I have a UIViewController that has two text fields, inputA
and inputB
. inputA
works like a normal text field, click it and the keyboard shows up and you can type. But inputB
triggers another view (think of it as a button). This second view, MyView
, has a custom popup view which is animated to appear with the keyboard. MyView
's popup is initially with the alpha to 0 and I have set notifications for when the keyboard shows up to have the popup's view alpha to be set to 1.
This works great, but I have a "bug" where when the keyboard is currently showing because the user tapped inputA first, then they tap inputB, it fires the MyView
but because the keyboard is already showing the notification isn't sent to change the popup alpha to 1.
So the question: what is the clean way to work around this issue? I want the view to appear along with the keyboard, but if it is already there, it should just be sent.
Is there a way to test if the keyboard is already showing? I want to do this without setting a bool value every time the keyboard is shown/hide in those two views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下
if ([inputA isFirstResponder] || [inputB isFirstResponder]){
//键盘显示
}else{
//键盘不显示
}
try the following
if ([inputA isFirstResponder] || [inputB isFirstResponder]){
//keyboard is displayed
}else{
//keyboard is not displayed
}