解决微信小程序中camera组件被view事件穿透触发对焦以及camera的bindtap事件
view跟camera组件同级
不要用bind:tap
和catch:tap
替换用catch:touchstart
即可解决!
如果你不放心,可以再加个透明蒙版,这样就不会触发了!(不加这个也行,但是必须要用catch:touchstart)
<!-- 相机层(横屏适配) --><camera device-position="back" resolution="high" frame-size="large" style="width: 100%; height: 100vh;z-index:10;" catch:touchstart="cameraClick" id="myCamera"></camera><!-- 在camera组件同级添加 --><view style="{{shieldStyle}}" catch:touchstart="noop"></view><!-- 你的业务view内容 --><view>xxx</view>
onReady() {// 双重保险:透明拦截层this.createTouchShield();},// 创建透明拦截层createTouchShield() {const query = wx.createSelectorQuery();query.select('#myCamera').boundingClientRect(rect => {console.log(rect)this.setData({shieldStyle: `position:absolute;left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px;z-index:999;pointer-events:auto;`});}).exec();},noop() {}, // 空函数吞噬所有事件