zoukankan      html  css  js  c++  java
  • textview键盘遮掩问题

    1,在viewdidload里面  写一个方法 

        [self registerKeyBoardAction];

    2,实现这个方法

    #pragma mark - 注册键盘弹起与消失事件

    -(void)registerKeyBoardAction{

        

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

        

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

    }

    -(void)keyBoardWillHideNotifcation:(NSNotification *)notifcation{

        //    [_detailsTX resignFirstResponder];

        [self.view resignFirstResponder];

        [self.view endEditing:YES];

        _myTableView.contentInset=UIEdgeInsetsZero;

        

    }

    #pragma mark - 键盘消失与显示通知方法

    -(void)keyBoardWillShowNotifcation:(NSNotification *)notifcation{

        

        self.view.frame = [[UIScreen mainScreen] bounds];

        

        //获取键盘的高度

        NSValue *value = notifcation.userInfo[@"UIKeyboardFrameEndUserInfoKey"];

        

        CGRect keyBoardFrame;

        [value getValue:&keyBoardFrame];

        _myTableView.contentInset=UIEdgeInsetsMake(0, 0,keyBoardFrame.size.height, 0);

    }

    以上方法不好用

    第二种  是针对textview键盘弹起

    -(void)textViewDidBeginEditing:(UITextView *)textView{

        if(textView == _textview){

            _textview = (JSTextView *)textView;

        }

        

        float offset = 0.0f;

        NSTimeInterval animationDuration = 0.30f;

        

        [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];

        

        [UIView setAnimationDuration:animationDuration];

        

        float width = _myTableView.frame.size.width;

        

        float height = _myTableView.frame.size.height;

        

        CGRect rect = CGRectMake(0.0f, offset-30 , width, height);

        

        _myTableView.frame = rect;

        

        [UIView commitAnimations];

    }

    -(void)textViewDidEndEditing:(UITextView *)textView{

        [UIView beginAnimations:@"ResizeForKeyBoard"context:nil];

        

        [UIView setAnimationDuration:0.3f];

        CGRect rect = CGRectMake(0.0f, 64 , SCREENWIDTH, SCREENHEIGHT-64);

        

        _myTableView.frame = rect;

        

        [UIView commitAnimations];

        

    }

    不好用

    第三种是第三方

    IQKeyboardManager 是第三方

    @property (nonatomic, strong) IQKeyboardReturnKeyHandler    *returnKeyHandler;

        self.returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];

        self.returnKeyHandler.lastTextFieldReturnKeyType = UIReturnKeyDone;

         [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;

  • 相关阅读:
    webpack指南(四)shimming
    webpack指南(三)缓存
    webpack指南(二)code spliting+懒加载
    webpack配置篇
    React组件setState
    React 生命周期
    React学习随笔
    @vue/cli 4.0+express 前后端分离实践
    @vue/cli 4.0.5 学习记录
    VMware Workstation 与 Device/Credential Guard 不兼容
  • 原文地址:https://www.cnblogs.com/liaolijun/p/5772030.html
Copyright © 2011-2022 走看看