监听键盘呼出事件的消息:
- [[NSNotificationCenter
defaultCenter] addObserver:self -
selector:@selector(keyboardWillShow:) -
name:UIKeyboardWillShowNotifi cation -
object:nil];
针对键盘高度做出自适应:
- -
(void)keyboardWillShow:(NSNotification *)notification - {
-
static CGFloat normalKeyboardHeight = 216.0f; //iphone键盘 -
NSDictionary *info = [notification userInfo]; -
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserIn foKey] CGRectValue].size; -
CGFloat distanceToMove = kbSize.height - normalKeyboardHeight; -
-
//自适应代码 - }
写了个小例子:
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
}