uni-app ios端使用第三方输入法(如搜狗)时,input组件首次不自动上推页面被键盘挡住,第二次聚焦才上推

uni-app ios端使用第三方输入法(如搜狗)时,input组件首次不自动上推页面被键盘挡住,第二次聚焦才上推

操作步骤:

  • 已经上传了代码

预期结果:

  • input第一次聚焦时应该上推页面不会被键盘挡住。

实际结果:

  • 第一次聚焦被挡住

bug描述:

  • 在iOS端,如果使用第三方输入法,例如搜狗输入法会第一次聚焦时,Input框不会自动上推页面。会被键盘挡住,第二次聚焦时才会上推页面。目前测试了只有在苹果端使用第三方输入法才会出现。亲测搜狗输入法。
  • 已经上传了例子

附件

image image

input_bug重现.zip


更多关于uni-app ios端使用第三方输入法(如搜狗)时,input组件首次不自动上推页面被键盘挡住,第二次聚焦才上推的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

自己写的临时解决方案
<template> <view class="content"> <image class="logo" src="/static/logo.png"></image> <view class="text-area"> <text class="title">{{title}}</text> </view> <input :adjust-position=“isFirst” @keyboardheightchange=“onKeyBoardHeightChange(res)” @focus=“test()” :focus=“isOpen” style=“margin-top: 500rpx;background-color: #fc3e35;” /> </view> </template>

<script> export default { data() { return { isOpen: true, title: 'Hello', isFirst: false //如果用户是第一次打开键盘就禁止输入框滚动,避免偶尔会引起页面闪动 } }, onReady() { }, onLoad() { } , methods: { test() { if (this.isOpen !== false) { uni.hideKeyboard(); //隐藏掉键盘 this.isFirst = true //接下来如果用户点击输入框就允许滚动 } this.isOpen = false; } } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .logo { height: 200rpx; width: 200rpx; margin-top: 200rpx; margin-left: auto; margin-right: auto; margin-bottom: 50rpx; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } </style>

更多关于uni-app ios端使用第三方输入法(如搜狗)时,input组件首次不自动上推页面被键盘挡住,第二次聚焦才上推的实战教程也可以访问 https://www.itying.com/category-93-b0.html


<template> <view class="content"> <image class="logo" src="/static/logo.png"></image> <view class="text-area"> <text class="title">{{title}}</text> </view> <input :adjust-position="isFirst" @keyboardheightchange="onKeyBoardHeightChange(res)" @focus="test()" :focus="isOpen" style="margin-top: 500rpx;background-color: #fc3e35;" /> </view> </template> <script> export default { data() { return { isOpen: true, title: 'Hello', isFirst: false //如果用户是第一次打开键盘就禁止输入框滚动,避免偶尔会引起页面闪动 } }, onReady() { }, onLoad() { } , methods: { test() { if (this.isOpen !== false) { uni.hideKeyboard(); //隐藏掉键盘 this.isFirst = true //接下来如果用户点击输入框就允许滚动 } this.isOpen = false; } } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .logo { height: 200rpx; width: 200rpx; margin-top: 200rpx; margin-left: auto; margin-right: auto; margin-bottom: 50rpx; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } </style>

这是一个iOS端第三方输入法与uni-app框架的兼容性问题。当使用搜狗等第三方输入法时,首次聚焦input组件可能无法正确触发页面上推机制,导致键盘遮挡输入框。

建议尝试以下解决方案:

  1. 在input组件的@focus事件中手动触发滚动:
handleFocus(e) {
  // 确保input组件可见
  setTimeout(() => {
    uni.pageScrollTo({
      scrollTop: e.detail.height,
      duration: 300
    })
  }, 100)
}
  1. 检查页面配置,确保在pages.json中正确设置了软键盘行为:
{
  "path": "pages/your-page",
  "style": {
    "app-plus": {
      "softinputMode": "adjustResize"
    }
  }
}
回到顶部