关闭

键盘上方工具条

200人阅读 评论(0) 收藏 举报
分类:

1.监听键盘设置Fram

1.1接受键盘通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardFramChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

1.2 改变工具条Fram

- (void)keyboardFramChange:(NSNotification *)notifaction
{
    NSLog(@"-----%@",notifaction.userInfo[@"UIKeyboardFrameEndUserInfoKey"]);
    CGRect y = [notifaction.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    _toolBar.y = y.origin.y - _toolBar.height;
}

2.改变工具条约束

2.1接受键盘通知

//添加键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillHide:) name:UIKeyboardWillHideNotification object:nil];

2.2 改变工具条约束

#pragma mark 键盘将显示
-(void)kbWillShow:(NSNotification *)noti{
    //显示的时候改变bottomContraint
    
    // 获取键盘高度
    NSLog(@"%@",noti.userInfo);
    CGFloat kbHeight = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
    
    
    self.bottomConstraint.constant = kbHeight;
}

#pragma mark 键盘将隐藏
-(void)kbWillHide:(NSNotification *)noti{
    self.bottomConstraint.constant = 0;

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20524次
    • 积分:1075
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:4篇
    • 译文:0篇
    • 评论:2条