UIKeyboardWillShowNotification
UIKeyboardWillShowNotification 通知来获得当键盘改变时,该键盘的高度和位置。
然后调整自己相应的UI元素位置即可,示例代码如下:
-(void)viewDidLoad{
[superviewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
-(void)viewDidUnload{
[superviewDidUnload];
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)keyboardWillShow:(NSNotification*)notification{
NSDictionary*info=[notification userInfo];
CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
NSLog(@"keyboard changed, keyboard width = %f, height = %f",
kbSize.width,kbSize.height);
//在这里调整UI位置
}