• 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;

  • 相关阅读:
    2020年全国安全生产月活动主题、挂图、招贴、标语、宣教用书等系列产品
    2020年安全生产月主题挂图指定宣教用品目录
    LNMP分离式部署步骤详解
    FTP文件传输服务
    DNS域名解析服务配置与测试
    DHCP服务搭建测试流程
    mysql数据库的操作
    mysql源码编译安装及其配置
    生产环境中ansible的安全处理
    http网页返回码详解
  • 原文地址:https://www.cnblogs.com/liaolijun/p/5772030.html
Copyright © 2020-2023  润新知