zoukankan      html  css  js  c++  java
  • iOS键盘遮挡住输入框解决办法

    1.设置键盘的类型,returnKeyType =UIReturnKeyDone;(可以根据具体情况设置键盘类型)

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{

        [self.view endEditing:YES];

          return YES;

    }

    2.发通知(针对scrollview设置contentSize    针对tableview设置y

     self.tableView.y = SCREEN_HEIGHT - self.keyBoardHeight -  self.tableView.height+64;

      [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardDidChangeFrameNotification object:nil];

    - (void)keyBoardChange:(NSNotification *)notification{

        NSDictionary *dict = notification.userInfo;

        NSValue *aValue = [dict objectForKey:UIKeyboardFrameEndUserInfoKey];

        NSNumber *animationTime = [dict objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"];

        

        CGRect keyboardRect = [aValue CGRectValue];

        CGFloat keyHeight = SCREEN_HEIGHT - keyboardRect.origin.y;

        if(keyHeight==0){

            [UIView animateWithDuration:[animationTime doubleValue] animations:^{

                self.scroll.contentSize = CGSizeMake(0,self.scrollHeight);

            } completion:^(BOOL finished) {

            }];

        }else{

              CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];

            CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];

            

            // 第三方键盘回调三次问题,监听仅执行最后一次

            if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){

                [UIView animateWithDuration:[animationTime doubleValue] animations:^{

                    

                    self.scroll.contentSize = CGSizeMake(0,self.scrollHeight + end.size.height);

                } completion:^(BOOL finished) {

                }];

                

            }else{

                

                [UIView animateWithDuration:[animationTime doubleValue] animations:^{

          

                    self.scroll.contentSize = CGSizeMake(0,self.scrollHeight + end.size.height);

                } completion:^(BOOL finished) {

                }];

                

            }

         }

    }

  • 相关阅读:
    PHP 学习轨迹
    beego 遇到的一些问题
    Fiddler 502问题
    SourceTree
    Trait
    PHP PSR 标准
    解决MySQL联表时出现字符集不一样
    Git 代码管理命令
    PHP 运行相关概念
    CentOS 7
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5694189.html
Copyright © 2011-2022 走看看