zoukankan      html  css  js  c++  java
  • 修改某个UITextField的键盘的返回键类型以及监听键盘的高度变化,取到键盘动画退出弹出的时间,一起随着键盘顶出来或者压下去,

    1、修改某个UITextField的键盘的返回键类型: 

    [_bottomTextView setReturnKeyType:UIReturnKeyDone];

    1.1、textFied点击return键之后有处理方法:

    UITextViewDelegate里面有这样一个代理函数:
    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)tex

     1.2、textView点击return键之后的处理:

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

        if ([text isEqualToString:@" "]){ //判断输入的字是否是回车,即按下return

            //在这里做你响应return键的代码

            [self.rejectReasonTextView resignFirstResponder];

            return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行

        }

        

        return YES;

    }

    ~~~~~~~~~~~~~~~~~~~~~

    以及监听键盘的高度变化,一起随着键盘顶出来或者压下去:

     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHeightChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

     keyboardHeightChange:

    -(void)keyboardHeightChange:(NSNotification *)notifi

    {

        self.dropButton.hidden = YES;

        NSDictionary *dict=[notifi userInfo];

        CGRect keyBoardRect=[[dict objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

        CGFloat keyBoardHeight=keyBoardRect.size.height;

        CGFloat keyBoardY=keyBoardRect.origin.y;

        float animationDuration = [[dict objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];//取到键盘动画退出弹出的时间,好处,不同的键盘时间可能不一样

        [UIView animateWithDuration:animationDuration animations:^{

            CGRect bottomNewFrame=CGRectMake(_bottomView.frame.origin.x, keyBoardY+_bottomView.frame.size.height, _bottomView.frame.size.width, _bottomView.frame.size.height);

            _bottomView.frame=bottomNewFrame;

        }];

  • 相关阅读:
    前端面试题汇总
    前端学习计划汇总
    idea修改项目名导致无法找到主类
    idea run dashbord使用
    记git提交异常
    关于META-INF下的spring.factories文件
    lombok注解
    springcloud-ribbon&feign
    CAP定理
    git文件锁定不更新和忽略
  • 原文地址:https://www.cnblogs.com/Jordandan/p/4975217.html
Copyright © 2011-2022 走看看