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) {

                }];

                

            }

         }

    }

  • 相关阅读:
    根据文件名或文件扩展名获取文件的默认图标
    TreeView实现类似Outlook在收件箱后面显示新邮件数
    取每组数据的第一条记录的SQL语句
    Stream 和 byte[] 之间的转换
    使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
    C# 创建临时文件
    Tomcat 服务不能启动的问题
    VS2008 椭圆曲线签名(ECDSA)
    2007年12月23日在博客园的排名进入了前300名
    现代软件工程 作业 3 团队作业
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5694189.html
Copyright © 2011-2022 走看看