uni-app 在iphone12或13pro上点击uni-popup弹出层会穿透到下面的input和textarea上调起输入框

uni-app 在iphone12或13pro上点击uni-popup弹出层会穿透到下面的input和textarea上调起输入框

14 回复

更多关于uni-app 在iphone12或13pro上点击uni-popup弹出层会穿透到下面的input和textarea上调起输入框的实战教程也可以访问 https://www.itying.com/category-93-b0.html


用示例代码hello uni-app能出现你的问题吗? 不能的话你需要排查出来具体你哪个页面,甚至哪一行导致的。 找出来具体原因后提供一个能复现你描述的bug的最小化demo,让我们及时定位问题,及时修复。 【bug优先处理规则】https://ask.dcloud.net.cn/article/38139

用示例代码hello uni-app加了几个input输入框上去能复现,视频在楼上

回复 w***@126.com: 仅在你说的iphone12或者13pro上出现吗?安卓有此问题吗?

回复 DCloud_UNI_Anne: 我只试了几款机型,发现这两款有问题,安卓没有发现问题

回复 w***@126.com: 看你录屏后几次弹框打开是正常的,刚进来的时候是操作了什么吗?出现弹框时有遮罩层应该是无法再点击底下的输入框的

回复 DCloud_UNI_Anne: 其实只是看上去正常,点击还是会穿透到input下面去,你看视频里面老是弹出输入框就是因为我点击了弹出框的取消按钮穿透到下面去了,刚我试了iphone XR也会穿透

复现视频

<template> <view class="container"> <uni-card is-full :is-shadow="false"> <text class="uni-h6">弹出层组件用于弹出一个覆盖到页面上的内容,使用场景如:底部弹出分享弹窗、页面插屏广告等。</text> </uni-card> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/> <input class="test" type="text" value="" placeholder="我是输入框"/>
    <uni-section title="对话框示例" type="line" class="hideOnPc">  
        <view class="example-body box">  
            <button class="button popup-success" @click="dialogToggle('success')"><text  
                    class="button-text success-text">成功</text></button>  
            <button class="button popup-error" @click="dialogToggle('error')"><text  
                    class="button-text error-text">失败</text></button>  
            <button class="button popup-warn" @click="dialogToggle('warn')"><text  
                    class="button-text warn-text">警告</text></button>  
            <button class="button popup-info" @click="dialogToggle('info')"><text  
                    class="button-text info-text">信息</text></button>  
        </view>  
    </uni-section>  
    <input type="text" value="" placeholder="我是输入框"/>  
    <uni-section title="输入框示例" type="line" padding>  
        <view class="dialog-box">  
            <text class="dialog-text">输入内容:{{ value }}</text>  
        </view>  
        <button class="button" type="primary" @click="inputDialogToggle"><text  
                class="button-text">输入对话框</text></button>  

    </uni-section>  
    <uni-section title="底部分享示例" type="line" padding>  
        <button class="button" type="primary" @click="shareToggle"><text class="button-text">分享模版示例</text></button>  
    </uni-section>  
    <view>  
        <!-- 普通弹窗 -->  
        <uni-popup ref="popup" background-color="#fff" @change="change">  
            <view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }"><text  
                    class="text">popup 内容</text></view>  
        </uni-popup>  
    </view>  

    <view>  
        <!-- 提示信息弹窗 -->  
        <uni-popup ref="message" type="message">  
            <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>  
        </uni-popup>  
    </view>  

    <view>  
        <!-- 提示窗示例 -->  
        <uni-popup ref="alertDialog" type="dialog">  
            <uni-popup-dialog :type="msgType" title="通知" content="欢迎使用 uni-popup!" @confirm="dialogConfirm"  
                @close="dialogClose"></uni-popup-dialog>  
        </uni-popup>  
    </view>  

    <view>  
        <!-- 输入框示例 -->  
        <uni-popup ref="inputDialog" type="dialog">  
            <uni-popup-dialog ref="inputClose" mode="input" title="输入内容" value="对话框预置提示内容!"  
                placeholder="请输入内容" @confirm="dialogInputConfirm"></uni-popup-dialog>  
        </uni-popup>  
    </view>  

    <view>  
        <!-- 分享示例 -->  
        <uni-popup ref="share" type="share">  
            <uni-popup-share></uni-popup-share>  
        </uni-popup>  
    </view>  
</view>  
</template> <script> export default { data() { return { type: 'center', msgType: 'success', messageText: '这是一条成功提示', value: '' } }, onReady() {}, methods: { change(e) { console.log('当前模式:' + e.type + ',状态:' + e.show); }, toggle(type) { this.type = type // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性 this.$refs.popup.open(type) }, messageToggle(type) { this.msgType = type this.messageText = `这是一条${type}消息提示` this.$refs.message.open() }, dialogToggle(type) { this.msgType = type this.$refs.alertDialog.open() }, dialogConfirm() { console.log('点击确认') this.messageText = `点击确认了 ${this.msgType} 窗口` this.$refs.message.open() }, inputDialogToggle() { this.$refs.inputDialog.open() }, dialogClose() { console.log('点击关闭') }, dialogInputConfirm(val) { uni.showLoading({ title: '3秒后会关闭' }) setTimeout(() => { uni.hideLoading() console.log(val) this.value = val // 关闭窗口后,恢复默认内容 this.$refs.inputDialog.close() }, 3000) }, shareToggle() { this.$refs.share.open() } } } </script> <style lang="scss"> .test{ text-align: center; width: 100%; } @mixin flex { /* #ifndef APP-NVUE */ display: flex; /* #endif */ flex-direction: row; } @mixin height { /* #ifndef APP-NVUE */ height: 100%; /* #endif */ /* #ifdef APP-NVUE */ flex: 1; /* #endif */ } .box { @include flex; } .button { @include flex; align-items: center; justify-content: center; flex: 1; height: 35px; margin: 0 5px; border-radius: 5px; } .example-body { background-color: #fff; padding: 10px 0; } .button-text { color: #fff; font-size: 12px; } .popup-content { @include flex; align-items: center; justify-content: center; padding: 15px; height: 50px; background-color: #fff; } .popup-height { @include height; width: 200px; } .text { font-size: 12px; color: #333; } .popup-success { color: #fff; background-color: #e1f3d8; } .popup-warn { color: #fff; background-color: #faecd8; } .popup-error { color: #fff; background-color: #fde2e2; } .popup-info { color: #fff; background-color: #f2f6fc; } .success-text { color: #09bb07; } .warn-text { color: #e6a23c; } .error-text { color: #f56c6c; } .info-text { color: #909399; } .dialog, .share { /* #ifndef APP-NVUE */ display: flex; /* #endif */ flex-direction: column; } .dialog-box { padding: 10px; } .dialog .button, .share .button { /* #ifndef APP-NVUE */ width: 100%; /* #endif */ margin: 0; margin-top: 10px; padding: 3px 0; flex: 1; } .dialog-text { font-size: 14px; color: #333; } </style>

点击红框区域都会调起输入框

遇到了同样的问题

同上,通用性的问题请尽快解决下

弹窗中有textarea,同样会无法调用软键盘。目前仅iOS

在 uni-app 中,弹出层(如 uni-popup)在 iOS 设备上点击后触发底层输入框(如 inputtextarea)的焦点问题,通常是由于 iOS 的事件处理机制和弹出层的遮罩层(mask)事件冒泡或穿透导致的。以下是针对此问题的专业分析和解决方案:

问题原因

  1. iOS 事件处理机制:iOS 设备对点击事件(tap)的处理较为特殊,尤其是在弹出层和输入框共存时,事件可能穿透到下层元素。
  2. 弹出层遮罩层事件未阻止冒泡uni-popup 的遮罩层默认可能未完全阻止事件冒泡,导致点击弹出层时,事件传递到底层输入框。
  3. 输入框焦点管理:底层输入框可能因事件触发而自动获取焦点,调起键盘。

解决方案

1. 为弹出层添加阻止事件冒泡的属性

  • uni-popup 组件中,确保遮罩层(mask)或内容区域添加 @tap.stop@touchmove.stop 来阻止事件冒泡。例如:
    <uni-popup ref="popup" @maskClick="closePopup">
      <view @tap.stop> <!-- 阻止点击事件冒泡 -->
        <!-- 弹出层内容 -->
      </view>
    </uni-popup>
    
  • 如果使用 uni-popup 的默认插槽,可以在内容容器上添加事件修饰符。

2. 动态控制输入框的禁用状态

  • 在弹出层显示时,通过代码禁用底层输入框的交互,隐藏时再启用。例如:
    <input :disabled="isPopupVisible" />
    <textarea :disabled="isPopupVisible" />
    
    export default {
      data() {
        return {
          isPopupVisible: false
        };
      },
      methods: {
        showPopup() {
          this.isPopupVisible = true;
          this.$refs.popup.open();
        },
        closePopup() {
          this.isPopupVisible = false;
          this.$refs.popup.close();
        }
      }
    };
    

3. 使用 pointer-events CSS 属性

  • 在弹出层显示时,为底层输入框添加 pointer-events: none; 样式,阻止其响应点击事件;隐藏时恢复为 auto。例如:
    <input :style="{ pointerEvents: isPopupVisible ? 'none' : 'auto' }" />
    
  • 注意:此属性在部分旧版本 iOS 中可能兼容性不佳,需测试目标设备。

4. 调整弹出层的 z-index 和层级结构

  • 确保弹出层的 z-index 值足够高(如 9999),并检查是否有其他元素层级干扰。同时,避免将输入框放在弹出层同级或更高层级。

5. 使用 uni.hideKeyboard() 强制隐藏键盘

  • 在弹出层显示时,调用 uni.hideKeyboard() 强制隐藏可能被调起的键盘。例如:
    showPopup() {
      uni.hideKeyboard(); // 隐藏键盘
      this.$refs.popup.open();
    }
回到顶部