您的位置:首页 > 产品设计 > UI/UE

UIKeyboardWillShowNotification 监听键盘高度变化

2015-02-02 16:38 357 查看
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位置

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: