项目中跟键盘相关方法总结

来源:互联网 发布:虚拟网络环境 编辑:程序博客网 时间:2024/05/01 19:13

增加点击事件

    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenKey)];    [_myTableView addGestureRecognizer:tap];
触发方法

- (void)hiddenKey {   [self.view endEditing:YES];}

防止键盘被覆盖

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

偏移

#pragma mark - keybord(监测键盘响应方法)- (void)keyboardWillShow:(NSNotification *)notification {    [UIView animateWithDuration:0.25 animations:^{        [_myTableView setContentOffset:CGPointMake(0, 300)];    } completion:nil];}- (void)keyboardWillHide:(NSNotification *)notification {    [UIView animateWithDuration:0.25 animations:^{        [_myTableView setContentOffset:CGPointMake(0, 0)];    } completion:nil];        }


0 0
原创粉丝点击