Hide or remove keyboard When Click UITextField(UITextView)

We could find the keyboard view When keyboardWillShow


-(void) viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:
self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

}
- (void)keyboardWillShow:(NSNotification *)note
{
NSDictionary *info = [note userInfo];
NSValue *keyBounds = [info objectForKey:UIKeyboardBoundsUserInfoKey];

CGRect bndKey;
[keyBounds getValue:&bndKey];


UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
//Get a reference of the current view
keyboard = [tempWindow.subviews objectAtIndex:i];

//Check to see if the description of the view we have referenced is "UIKeyboard" if so then we found
//the keyboard view that we were looking for
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
{
[keyboard removefromesuperview];
break;
}
}
}
发布了17 篇原创文章 · 获赞 6 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/jacky_jin/article/details/5418315