ios监视键盘高度,防止输入时遮挡页面内容。
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark -
#pragma mark -Keyboard
- (void) registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil];
}
- (void) keyboardWasShown:(NSNotification *) notif
{
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
[self.dataTableView setFrame:CGRectMake(0, 0, self.dataTableView.frame.size.width, self.view.frame.size.height - keyboardSize.height)];
}
- (void) keyboardWasHidden:(NSNotification *) notif
{
[self.dataTableView setFrame:CGRectMake(0, 0, self.dataTableView.frame.size.width, self.view.frame.size.height)];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self registerForKeyboardNotifications];
}