一.定位键盘视图
@implementation UIApplication(KeyboardView)
- (UIView*)keyboardView
{
char* keyBoardViewClassName = NULL;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
keyBoardViewClassName = "UIPeripheralHostView";
}
else {
keyBoardViewClassName = "UIKeyboard";
}
NSArray *windows = [self windows];
for(UIWindow *window in [windows reverseObjectEnumerator])
{
for(UIView *view in [window subviews])
{
if(!strcmp(object_getClassName(view), keyBoardViewClassName))
{
return view;
}
}
}
return nil;
}
@end
二.定位firstResponder
UIView *firstResponder = [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)];
参考:
Showing a “Loading…” message over the iPhone keyboard
UIKeyboardTypeNumberPad键盘增加Return键
object_getClassName
keyWindow