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;

  • 相关阅读:
    log4j使用教程
    (POI)Excel格式转Html格式
    log4j2使用教程
    Spring AOP 面向切面编程入门
    C# 标准事件模式
    1Angular的MVC和作用域
    3Angular的模块化
    2Angular的双向数据绑定(MVVM)
    5手动初始化Angular的模块与控制器
    python读取 UCS2 little endian(utf16le) 格式的文件
  • 原文地址:https://www.cnblogs.com/liaolijun/p/5772030.html
Copyright © 2011-2022 走看看