I have set a inputAccessoryView as Referencing Outlet of the XIB’s file View which has the buttons for an optional keyboard. That makes the View be shown when the Standard Keyboard is shown and be hidden when the Standard Keyboard is hidden.
It is also necessary to hide the optional keyboard when it gets a tap in its middle zone. This makes it be hidden while the Standard Keyboard is still showing. To do this, I also set another Property as Referencing Outlet of the same XIB’s file View.
I’m hiding the optional keyboard setting its frame’s origin.y to a high number:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
viewOptionalKeyboard.frame = CGRectMake(viewOptionalKeyboard.frame.origin.x, 1200, viewOptionalKeyboard.frame.size.width, viewOptionalKeyboard.frame.size.height);
[UIView commitAnimations];
[UIView setAnimationDuration:0];
This makes the optional keyboard be hidden, but the animation goes on top of the standard keyboard and not behind. You can see the auxiliar keyboard go all over the Window from up to down until it gets hidden.
Is there a way to hide it “behind” the Standard Keyboard so it’s hiding process looks better?
I edited this question because the hiding is working well now with Chris’s answer that suggested changing the size of the View.
Now the problem is about showing it again: when I tap a button, the view should be shown again with the same size. In the button tap event I added this code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
viewOptionalKeyboard.frame = CGRectMake(viewOptionalKeyboard.frame.origin.x, 500, viewOptionalKeyboard.frame.size.width, 74);
[UIView commitAnimations];
[UIView setAnimationDuration:0];
This is to set the optional keyboard its original size and its original y position. It gets its original position, but there are 2 things that makes it wrong:
1) It is shown over/on top the Standard Keyboard, so we return to the hiding problem, but now when showing. Again, you can see the optional keyboard come all over the window from downwards until it gets its original position.
2) The buttons which belong to the main View that contains the optional keyboard come short sized as if they had been crushed.
Which is the best way to present the keyboard again avoiding this problems?
Why don’t you reduce the height of the view at the same time that you move the y point?
You just need to make sure that the subviews have a flexible height auto resizing mask.
Edit: Now that the question has changed to require the view to hide/show, the answer has changed too
You’ll need an ivar or property to keep track of the original frame height:
And then in your method for showing/hiding, you can check whether the viewOptionalKeyboard frame is visible, and act accordingly: