iOS 键盘处理

来源:互联网 发布:家谱制作软件下载 编辑:程序博客网 时间:2024/06/08 00:07

  [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyBoardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];

    // 键盘即将隐藏, 就会发出UIKeyboardWillHideNotification

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyBoardWillHide:)name:UIKeyboardWillHideNotificationobject:nil];


/**

 *  键盘即将弹出

 */

- (void)keyBoardWillShow:(NSNotification *)note

{

    // 1.键盘弹出需要的时间

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

    

    // 2.动画

    [UIViewanimateWithDuration:duration animations:^{

        // 取出键盘高度

        CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];

        CGFloat keyboardH = keyboardF.size.height;

        self.bottomView.transform = CGAffineTransformMakeTranslation(0, - keyboardH);

    }];

}

#pragma mark - 键盘处理

/**

 *  键盘即将隐藏

 */

- (void)keyBoardWillHide:(NSNotification *)note

{

    //    if (self.isChangingKeyboard) return;

    

    // 1.键盘弹出需要的时间

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

    

    // 2.动画

    [UIViewanimateWithDuration:duration animations:^{

        self.bottomView.transform =CGAffineTransformIdentity;

    }];

}



0 0
原创粉丝点击