Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent keyboard from dismissing while pushing view controller

I am having a hard time controlling keyboard behavior when I push a UIViewController using pushViewController:animated: The from view contains some UITextFields but the to view has none. If the keyboard is present at the time of the push, it self-resigns automatically alongside the horizontal push animation. It's a little jarring to see the from view slide down at the same time as the to view slides in.

Can I have the keyboard maintain its position and slide horizontally out of view with the from controller? I've certainly seen this done the other way round, where the to controller has a presented keyboard sliding in from the left when pushed.

like image 395
Ben Packard Avatar asked Jan 13 '15 06:01

Ben Packard


1 Answers

I, too, am not sure this is possible. Basically you have to add the keyboard as a subview of the current view in prepareForSegue. I don't know if you can do that with the keyboard.

If not, you can sorta cheat by doing the following in prepareForSegue:

  1. Taking a screen shot of the portion of the view containing the keyboard
  2. Add the screen shot to the view as a subview
  3. Dismiss the keyboard without animation
like image 107
Josh Gafni Avatar answered Sep 30 '22 07:09

Josh Gafni