iOS 自定义键盘ToolBar(与键盘的弹出、收起保持一致)

1、监听键盘改变的通知

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

  

2、实现通知方法

/**

 *  给键盘的frame改变添加监听

 *  @param keyBoardWillChangeFrame: 监听方法

 */

- (void)keyBoardWillChangeFrame:(NSNotification*)notification{

    // 键盘显示隐藏完毕的frame

    CGRect frame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

    // 动画时间

    CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    if (frame.origin.y == JYEScreenHeight) { // 没有弹出键盘

        [UIView animateWithDuration:duration animations:^{

            self.toolBarView.transform =  CGAffineTransformIdentity;

        }];

    }else{ // 弹出键盘

        // 工具条往上移动258

        [UIView animateWithDuration:duration animations:^{

            self.toolBarView.transform = CGAffineTransformMakeTranslation(0, -frame.size.height-64);

        }];

    }

}
原文地址:https://www.cnblogs.com/lrr0618/p/6119177.html