在很多時候會需要獲取彈出鍵盤的高度來進行動態布局這個時候根據不同的機型大小是不同的這時候就應該動態獲取
實現步驟?
1.利用觀察者 來監聽是否彈出鍵盤
//監聽彈出鍵盤
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//可以監聽收回鍵盤
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//創建觀察者回調方法
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//創建自帶來獲取穿過來的對象的info配置信息
NSDictionary *userInfo = [aNotification userInfo];
//創建value來獲取 userinfo里的鍵盤frame大小
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
//創建cgrect 來獲取鍵盤的值
CGRect keyboardRect = [aValue CGRectValue];
//最后獲取高度 寬度也是同理可以獲取
int height = keyboardRect.size.height;
}