旋转时键盘隐藏
我正在开发 iPad 应用程序。在其中一个视图中,我有一个子视图,它在按钮点击事件时出现和消失。子视图包含一个 UITextView。默认情况下,我将其设置为第一响应者,以便在视图出现时键盘立即出现。当 UIKeyboardWillHideNotification 被触发时,子视图也会消失,即键盘被隐藏。
现在的问题是,一旦应用程序旋转,系统就会触发 UIKeyboardWillHideNotification,从而使子视图消失。我希望键盘保留在屏幕上。
这是怎么回事,我该如何解决它!?
注意:视图和子视图都有单独的视图控制器。 UIKeyboardWillHideNotification 在子视图的视图控制器类中接收。
I'm working on an iPad application. In one of it's views, i have a subview which appears and disappears on button tap event. The subview contains a UITextView
. By default i make it the first responder so that the keyboard appears as soon as the view appears. The subview also disappears when UIKeyboardWillHideNotification
is fired i.e. keyboard is hidden.
Now, the problem is that as soon as the application is rotated, UIKeyboardWillHideNotification
is fired by the system, which in turn make the subview disappear. I want the keyboard to remain on screen.
What's going on, and how can i fix it!?
Note: Both the view and subview have separate view controllers. UIKeyboardWillHideNotification is received in subview's view controller class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 shouldAutoRotate 方法中声明一个 BOOL 变量,并在调用它时设置该变量,然后在用于显示和隐藏子视图的选择器方法中,您可以使用一个简单的 if 条件来判断天气视图是否旋转。
像这样:
编辑部分:
我不确定这段代码发生了什么,但它在我的一个应用程序中完美运行,该应用程序的 ipad 编码是由我的朋友完成的。
如果您的 UIKeyboardWillHideNotification 未通过在此方法中再次添加这些通知而触发,您可以再次添加通知。
You can declare a BOOL variable in shouldAutoRotate method and that is set when it is called and then in the selector method for showing and hiding the subview you can use a simple if condition that weather view is rotated or not.
like this:
Edit Part:
I am not sure whats going on in this code but its working perfectly in one of my apps who's ipad coding was done by my friend.
And you can add the notification again if your UIKeyboardWillHideNotification is not fired by add those notification again in this method.
您可以使用 BOOL 变量来记录它是否正在旋转。那么当它旋转时你就什么也不能做。
You can use a BOOL variable to recording whether it's rotating. Then you can do nothing when it's rotating.