Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent hiding keyboard on presentViewController (showing popup)

There is a view with UITextView on it. UITextView is the only one possible firstResponder for keyboard. Let's call it "BackView".

There is another view which is PopUp (full screen view with transparent background which fades underlying view). Let's call it "PopUp".

PopUp works fine except when the keyboard is on screen. Presenting PopUp forces keyboard to be hidden and, when the PopUp is dismissed, the keyboard is shown again. Since the PopUp is not covering whole BackView it does not look good.

Is there any way to keep keyboard on BackView while PopUp is shown? (there is no need to use keyboard in popup).

PopUp contains:

  • full screen view with background set to black colour with alpha (to fade underlaying view)
  • several images, labels and Close button.

PopUp is shown with:

[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentViewController:vc animated:YES completion:nil];

Found solution:

Add PopUp view as a subview for current window

like image 328
mb.sever Avatar asked Jul 03 '14 15:07

mb.sever


1 Answers

mb.server answered his own question (one that I had as well). But I just wanted to spell out the code explicitly for the benefit of others:

//instantiate popUpVC, then
popUpVC.view.frame = [UIScreen mainScreen].bounds; //assuming you wish the popover to occupy the entire screen; adjust as needed
UIWindow* currentWindow = [[[UIApplication sharedApplication] windows] lastObject];
[currentWindow addSubview:popUpVC.view];
like image 105
T'Pol Avatar answered Sep 23 '22 23:09

T'Pol