微信6.7.4 ios12 软键盘收回时页面不回弹,导致光标位置错乱,再次点击输入框区域时无法focus

https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800

https://blog.csdn.net/qq_23370345/article/details/84757505

参考上述文章,可解决,补充多个输入框处理方法:

   /* 问题: ios12+,微信6.7.4版本存在bug,键盘收回时,界面没有恢复,底下出现空白区域,并导致光标位置错乱,再次点击输入框区域时无法focus
         解决方案: 当input失焦,键盘收回后,滚动一下页面就可以使页面恢复正常
         补充: 当在手机号与验证码之间切换输入时,会同时触发前输入框的blur和后输入框focus,这个时候触发滚动,页面会出现较大跳跃,因此通过inFocus 和 setTimeout 判断,是切换input还是真正blur,真正blur的时候,再滚动页面
      */
      //focus
      iptFocus () {
         this.errorMessage = '';
         this.inFocus = true;
      },
      //blur
      iptBlur () {
         let this_ = this;
         this_.inFocus = false;
         setTimeout(function () {
            if(this_.inFocus == false){
               // 当input 失焦时,滚动一下页面就可以使页面恢复正常
               this_.checkWxScroll();
            }
         },200)
      },

      checkWxScroll(){
         var ua = navigator.userAgent.toLowerCase();
         var u = navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

         if(ua.match(/MicroMessenger/i) == 'micromessenger'&&!!u){//在iphone 微信中
//            var osVersion  =  navigator.userAgent.match(/iPhone\sOS\s([\d\_]+)/i);
//            var  osArr = osVersion.length>=1? osVersion[1].split('_'):[];
//            var newOS = osArr.length>=2 && (versionArr[0]>11)
//            if(newOS){ //如果iphone版本号>=12
               this.temporaryRepair();
//            }
         }
      },
      temporaryRepair(){
         var currentPosition,timer;
         var speed=1;//页面滚动距离
         timer=setInterval(function(){
            currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
            currentPosition-=speed;
            window.scrollTo(0,0);//页面向上滚动
//            currentPosition+=speed; //speed变量
//            window.scrollTo(0,currentPosition);//页面向下滚动
            clearInterval(timer);
         },1);
      },

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值