Keyboard hides when spinning

I am working on an iPad application. In one of his views, I have a subview that appears and disappears when a button is clicked. The subsection contains a UITextView . By default, I make this the first responder so that the keyboard appears as soon as the view appears. The subview also disappears when starting UIKeyboardWillHideNotification , i.e. The keyboard is hidden.

Now the problem is that as soon as the application is rotated, the UIKeyboardWillHideNotification system UIKeyboardWillHideNotification started by the system, which, in turn, leads to the disappearance of the view. I want the keyboard to stay on the screen.

What is happening and how can I fix it?

Note. Both views and subtitles have separate view controllers. UIKeyboardWillHideNotification is obtained in the view controller class.

+4
source share
2 answers

You can declare a BOOL variable in the shouldAutoRotate method and set it when it is called, and then in the selection method to display and hide the subtitle, you can use a simple condition when the weather window rotates or not.

like this:

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

Change part:
I'm not sure what is going on in this code, but it works fine in one of my applications, the ipad encoding of which was done by my friend.

 - (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; } 

And you can add a notification again if your UIKeyboardWillHideNotification is not running by adding this notification again to this method.

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
+4
source

You can use the BOOL variable to record its rotation. Then you can do nothing when it spins.

+1
source

All Articles