开发者

Howto get the Keyboard UIView on iPhone, iOS 3.2 or newer

I'm using a trick to overlay the keyboard with my own. Basically I add some buttons as Subviews to the Keyboard. This is how I find the UIView of the keyboard:

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(UIView* potentialKeyboard in tempWindow.subviews)
    // if the real keyboard-view is found, remember it.
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        if([[potentialKeyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
            keyboard = potentialKeyboard;
        }
        else {
            if([[potentialKeyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                keyboard = potentialKeyboard;
    }

This method is called by the UIKeyboardDidShowNotification. I'd rather have it called by UIKeyboardWillShowNotification, since the "Did" version shows after the original keyboard is shown to the user. But if I use the same procedure as above it produces a EXC_BAD_ACCESS error. Apparently the keyboard's view is not found properly.

Now my question: Is there any way to开发者_StackOverflow access the keyboard's UIView at the time UIKeyboardWillShowNotification is fired.

Thanks in advance


I added simply used this [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

and

- (void)keyboardWillShow { [self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0]; } .

This is called when keyboard is going to appear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜