UITextfield获取焦点时,进入textFieldShouldBeginEditing方法,在这个方法中注册两个通知:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
//隐藏键盘
- (void)keyboardWillShow:(NSNotification *)Notification{
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
[tempWindow setAlpha:0];
}
//显示自定义键盘- (void)keyboardWasShown:(NSNotification *) Notification{
// 显示自定义键盘
}