键盘大小变化时,系统会发出 UIKeyboardWillShowNotification 通知,我们只要监听这个通知,并在响应函数里处理界面布局就行。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updatePositionAccordingKeyboardBounds:)
name:UIKeyboardWillShowNotification object:nil];
- (void) updatePositionAccordingKeyboardBounds:(id)sender
{
CGRect keyboardbounds;
[[[((NSNotification*)sender) userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]
getValue:&keyboardbounds];
int keyboard_height = CGRectGetHeight(keyboardbounds);
//update ui layout here
}