键盘隐藏在旋转上

我正在开发一个iPad应用程序。 在其中一个视图中,我有一个子视图,在按钮点击事件中显示和消失。 子视图包含UITextView 。 默认情况下,我将其设为第一个响应者,以便在视图出现时立即显示键盘。 当UIKeyboardWillHideNotification被触发时,子视图也会消失,即键盘被隐藏。

现在,问题在于,一旦旋转应用程序, UIKeyboardWillHideNotification就会触发UIKeyboardWillHideNotification ,从而使子视图消失。 我希望键盘保持在屏幕上。

发生了什么,我该怎么办呢!?

注意:视图和子视图都有单独的视图控制器。 UIKeyboardWillHideNotification在子视图的视图控制器类中接收。

您可以在shouldAutoRotate方法中声明一个BOOL变量,并在调用它时设置该变量,然后在显示和隐藏子视图的选择器方法中,您可以使用简单的if条件来旋转天气视图。

喜欢这个:

 if(viewRotated) { subView.hidden = YES; } viewRotated = NO; 

编辑部分:
我不确定这段代码中是什么,但它在我的一个应用程序中完美地工作,我的朋友已经完成了ipad编码。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillShowNotification object:nil]; } else { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } return YES; } 

如果未通过在此方法中再次添加这些通知来触发您的UIKeyboardWillHideNotification,则可以再次添加通知。

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

您可以使用BOOL变量来记录它是否在旋转。 然后你在旋转时什么都不做。