监听键盘弹出高度
- (void)registerForKeyboardNotifications
{//使用NSNotificationCenter 鍵盤出現時[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillShown:)name:UIKeyboardWillChangeFrameNotification object:nil];//使用NSNotificationCenter 鍵盤隱藏時[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillBeHidden:)name:UIKeyboardWillHideNotification object:nil];
}//實現當鍵盤出現的時候計算鍵盤的高度大小。用于輸入框顯示位置
- (void)keyboardWillShown:(NSNotification*)aNotification
{
NSDictionary *info = [notification userInfo];
? ? CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
? ? NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
? ? CGSize keyboardSize = [value CGRectValue].size;
?? ?
?
//輸入框位置動畫加載?
? ? [UIView animateWithDuration:duration animations:^{
//do something
?
? ? }];
}
//當鍵盤隱藏的時候- (void)keyboardWillBeHidden:(NSNotification*)aNotification{ //do something}轉載于:https://www.cnblogs.com/670074760-zsx/p/6834272.html
總結
- 上一篇: VB2010(18)_各种对话框的使用
- 下一篇: 清除浮动造成的影响的解决方案总结