我正在使用一个技巧来用自己的键盘覆盖键盘。基本上,我将一些按钮作为子视图添加到键盘。这是我找到键盘的UIView的方法:

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;
    }


UIKeyboardDidShowNotification调用此方法。我希望它由UIKeyboardWillShowNotification调用,因为“ Did”版本是在向用户显示原始键盘之后显示的。但是,如果我使用与上述相同的过程,则会产生EXC_BAD_ACCESS错误。显然找不到键盘的视图。

现在我的问题是:有什么方法可以在触发UIKeyboardWillShowNotification时访问键盘的UIView。

提前致谢

最佳答案

我添加的只是使用了[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];



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


当键盘将要出现时调用此方法。

08-15 20:36