美文网首页iOS基本功
iOS 键盘弹出收回高度时间

iOS 键盘弹出收回高度时间

作者: 此时_此景 | 来源:发表于2018-12-13 10:48 被阅读0次

//监听当键盘将要出现时

    [[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*)notification

{

    //获取键盘的高度

    NSDictionary*userInfo = [notificationuserInfo];

    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    // 1,取出键盘动画的时间

    CGFloat duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    CGRectkeyboardRect = [valueCGRectValue];

    intheight = keyboardRect.size.height;

    [UIView animateWithDuration:duration animations:^{

        self.bottomBar.frame = CGRectMake(0, BAScreenHeight  -TABBARHEIGHT-height+2, BAScreenWidth, TABBARHEIGHT-2);

    }];

}

//当键退出

- (void)keyboardWillHide:(NSNotification*)notification

{

    //获取键盘的高度

    NSDictionary*userInfo = [notificationuserInfo];

    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRectkeyboardRect = [valueCGRectValue];

    CGFloat duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    intheight = keyboardRect.size.height;

    [UIView animateWithDuration:duration animations:^{

        self.bottomBar.frame = CGRectMake(0, BAScreenHeight  -TABBARHEIGHT, BAScreenWidth, TABBARHEIGHT-2);

    }];

}

相关文章

网友评论

    本文标题:iOS 键盘弹出收回高度时间

    本文链接:https://www.haomeiwen.com/subject/onjvhqtx.html