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

                }];

                

            }

         }

    }

  • 相关阅读:
    jquery 回调函数
    彻底弄懂js循环中的闭包问题
    浅谈JavaScript for循环 闭包
    eclipse maven工程resources目录下的文件夹是包图标解决
    筛选载入的HTML文档
    记坑: ConfigurationProperties 和 RefreshScope
    记坑: ConfigurationProperties 和 RefreshScope
    利用simhash计算文本相似度
    利用simhash计算文本相似度
    利用simhash计算文本相似度
  • 原文地址:https://www.cnblogs.com/hongyan1314/p/5694189.html
Copyright © 2020-2023  润新知