iOS监听键盘的高度 隐藏和出现

释放双眼,带上耳机,听听看~!

1.注册检测键盘的通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    //注册键盘隐藏通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardHide:) name: UIKeyboardWillHideNotification object:nil];

2.键盘出现的函数

#pragma mark - 键盘出现函数
- (void)keyboardWasShown:(NSNotification *)notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    _keyboardSize = keyboardSize.height;
    
}

3.键盘隐藏的函数

#pragma mark - 键盘关闭函数
-(void)keyboardHide:(NSNotification *)notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    _keyboardSize = keyboardSize.height;   
}

 

人已赞赏
iOS文章

iOS 多个UIScrollView嵌套解决方案

2019-10-28 17:24:21

iOS文章

iOS巧妙实现悬浮tableviewHeaderView方法

2019-10-28 19:25:50

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索