uni-app IOS中uview框架的u-input组件及uni-app的input组件软键盘弹出后立即收起问题

uni-app IOS中uview框架的u-input组件及uni-app的input组件软键盘弹出后立即收起问题

4 回复

在安卓端软键盘都是正常的

更多关于uni-app IOS中uview框架的u-input组件及uni-app的input组件软键盘弹出后立即收起问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html


好像是因为在subNvue页面中,两次隐藏软键盘引起的 把quit方法中的uni.hideKeyboard(); 注释掉以后就好了
methods: {
hide() {
uni.hideKeyboard();
setTimeout(() => {
this.quit();
}, 200);
},
heightChange(e) {
if (e.detail.height <= 0) this.quit();
},
handleSend(){
if(this.commentContent == ‘’){
return
}
uni.$emit(send-comment,this.commentContent);
this.hide();
},
quit() {
uni.hideKeyboard();
this.commentContent = ‘’;
uni.getSubNVueById(‘input’).hide();
}
}

你好,想问一下这里的 quit 方法是在哪里呢?

这是一个常见的iOS软键盘兼容性问题。在uni-app中使用u-input或原生input组件时,iOS上可能会出现键盘弹出后立即收起的情况。主要原因和解决方案如下:

  1. 主要原因:
  • iOS对input的focus处理机制不同
  • 页面滚动或布局变化导致输入框失去焦点
  • 第三方组件库(uview)可能存在的兼容性问题
  1. 解决方案:

(1) 基础方案:

// 在focus事件中延迟处理
onFocus() {
    setTimeout(() => {
        this.$refs.input.focus()
    }, 300)
}

(2) 针对u-view的u-input组件:

<u-input 
    v-model="value"
    @focus="handleFocus"
    :focus="isFocus"
/>

handleFocus() {
    this.isFocus = true
    setTimeout(() => {
        this.isFocus = true // 保持焦点状态
    }, 100)
}
回到顶部