【开发笔记】监听键盘的那些事

【开发笔记】监听键盘的那些事_第1张图片

复制:

- (void)registerForKeyboardNotifications{

    //使用NSNotificationCenter 鍵盤出現時

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillShown:)

                                                 name:UIKeyboardWillChangeFrameNotificationobject:nil];

    //使用NSNotificationCenter 鍵盤隐藏時

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillBeHidden:)

                                                 name:UIKeyboardWillHideNotificationobject:nil];

}

//实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置

- (void)keyboardWillShown:(NSNotification*)aNotification{

    NSDictionary*info = [aNotificationuserInfo];

    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSizekeyboardSize = [valueCGRectValue].size;

    //输入框位置动画加载

    [UIView animateWithDuration:0.3 animations:^{

        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    //self.sendView 是 输入框控件

//        self.sendView.y = [] - 44 - 64 - keyboardSize.height;

    }completion:^(BOOLfinished) {

    }];

}

//当键盘隐藏的时候

- (void)keyboardWillBeHidden:(NSNotification*)aNotification{

    [UIView animateWithDuration:0.3 animations:^{

        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        //self.sendView 是 输入框控件

//        self.sendView.y = kScreenHeight - 44 - 64;

    }completion:^(BOOLfinished) {

    }];


}

你可能感兴趣的:(【开发笔记】监听键盘的那些事)