监控KeyBoard
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:)name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHidden:)name:UIKeyboardWillHideNotification object:nil];
显示的实现
- (void) keyBoardWillShow:(NSNotification*) notification
{
NSDictionary *userInfo = [notification userInfo];
// Get the origin of the keyboard when it's displayed.
NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
// Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
CGRect keyboardEndFrame = [aValue CGRectValue];
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
CGFloat keyboardHeight = keyboardFrame.size.height;
}
本文介绍了如何使用Objective-C监听UIKeyboardWillShowNotification和UIKeyboardWillHideNotification通知,以实现对键盘显示与隐藏的监控。
289

被折叠的 条评论
为什么被折叠?



