我正在使用一种技巧来覆盖原有的键盘。基本上,我将一些按钮添加为键盘的子视图。以下是我查找键盘的 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。
提前致谢。