ios处理键盘

#pragma mark - Keyboard

- (void)addKeyboardNoti {

    

    [[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 *)sender {

    

    if(!self.isKeyboardShow){

        

        //获取键盘的frame

        CGRect keyboardFrame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

        // 修改tableView frame

        [UIView animateWithDuration:0 animations:^{

            CGRect frame = self.paramTableView.frame;

            frame.size.height = frame.size.height - keyboardFrame.size.height;

            self.paramTableView.frame = frame;

        }];

        

        self.isKeyboardShow = true;

    }

    

}

- (void)keyboardWillHide:(NSNotification *)sender {

    

    if(self.isKeyboardShow){

        self.paramTableView.frame = self.tableViewFrame;

        self.isKeyboardShow = false;

    }

    

}

猜你喜欢

转载自www.cnblogs.com/iOS-mt/p/9253196.html