iOS 监听键盘的弹出,收起,并且拿到键盘的高度

//监听当键盘将要出现时

[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];

//监听当键将要退出时

[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotificationobject:nil];

//当键盘出现

- (void)keyboardWillShow:(NSNotification *)notification{

//获取键盘的高度NSDictionary *userInfo = [notification userInfo];

NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect = [value CGRectValue];int height = keyboardRect.size.height;

}

//当键退出

- (void)keyboardWillHide:(NSNotification *)notification{

//获取键盘的高度NSDictionary *userInfo = [notification userInfo];

NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect = [value CGRectValue];

int height = keyboardRect.size.height;

}

转载:http://www.cocoachina.com/bbs/read.php?tid-329755.html

你可能感兴趣的:(iOS 监听键盘的弹出,收起,并且拿到键盘的高度)