0

I hope to insert subview in front of displayed keyboard. I am using the following code:

[self.view bringSubviewToFront: myView];

but the subview does not display.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
arachide
  • 8,006
  • 18
  • 71
  • 134
  • 1
    What you really want to do? Because showing a view in front of a "key board" doesn't make a sense. I am sure that you missed something in asking your question. Expand your question with more details that exactly you wants to do. Put any screen shots too if you've. – Hemang Mar 26 '12 at 11:07

3 Answers3

2

I am not exactly sure what you are looking for, but my best guess is you want to subview a "done"/"return" over the keypad. You maybe able to do this by doing something like this (when the keyboard comes up)

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];  
UIView* keyboard;  
for(int i=0; i<[tempWindow.subviews count]; i++)   
{
    keyboard = [tempWindow.subviews objectAtIndex:i];  
    // keyboard view found; add the custom button to it  
    if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)  
        [keyboard addSubview:doneButton];  
}  

The bringSubviewToFront idea failed because it (the keyboard) is not a subview of your application.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Altaf
  • 71
  • 5
  • From what I can see on iOS 7, the windows property doesn't always have 2 windows. On iOS 8 though, this seems to work properly. – alexgophermix Jul 23 '15 at 20:57
0

Credit to Artyom from this question

Rather than using this for loop to find the correct window you can instead use:

UIWindow * window = [UIApplication sharedApplication].windows.lastObject;

[window addSubview:_menuView];
[window bringSubviewToFront:_menuView];

As long as you are adding it while the is keyboard active then the keyboard will always be the last view added and it reduces the code complexity greatly.

Community
  • 1
  • 1
sam_smith
  • 6,023
  • 3
  • 43
  • 60
0

@Altaf, the prefix you mention in your code is not the good one. You should use:

if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)

See an example, with Touchpose classes to show touches on demo applications, that I modified to display the animation over the keyboard.

Community
  • 1
  • 1
Denis
  • 775
  • 7
  • 22