iphoneiphone-softkeyboard

How do I place a subview in front of the keyboard?


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.


Solution

  • 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.