uniapp在app上如何实现类似微信按住不放发送语音的功能?
网友回复
这个需要用到三个事件
首先给按钮是绑定事件,需要给按钮绑定三个事件1.touchstart事件会在触摸按钮时触发,可以获取手指的初始坐标;2.touchmove事件在触摸后移动手指时触发,可以用来计算手手指的滑动距离;3.touchend事件在松开手指时候触发。
<button type="default" v-show="mode === 'voice'" @touchstart="handleTouchStart" @touchmove="handleTouchMove" @touchend="handleTouchEnd" >按住 说话</button>三个
const recorderManager = uni.getRecorderManager();
// 开始录制语音
handleTouchStart(e){
this.mask = true;
recorderManager.start();
this.length = 1;
this.startX = e.touches[0].pageX;
this.startY = e.touches[0].pageY;
...点击查看剩余70%
还有一个页面遮罩层
<!-- 语音遮罩层 -->
<view class="voice-mask" v-show="mask">
<!--语音条 -->
<view class="voice-bar voice-del" :class="{voiceDel:needCancel}" :style={width:getVoiceBarWidth}>
<image src="../static/icon/wave.png" class="voice-volume" :class="{volumeDel:needCancel}"></image>
<view class="trangle-bottom" :class="{trangleDel:needCancel}"></view>
</view>
<!-- 底部区域 -->
<view class="voice-send">
<!-- 取消和转文字图标 -->
<view class="voice-middle-wrapper">
<!-- 取消 -->
<view class="voice-left-wrapper">
<view class="cancel-del" :class="{delTip:needCancel}">松开 取消</view>
<view class="voice-middle-inner close" :class="{bigger:needCancel}">
<image src="../static/icon/close-grey.png" class="close-icon"></image>
</view>
</view>
<!-- 转文字 -->
<view class="voice-middle-inner to-text">
<text class="wen">文</text>
<!-- <image src="" class="wen"></image> -->
</view>
<view class="send-tip" :class="{sendTipNone:needCancel}">松开 发送</view>
</view>
<!-- 底部语音按钮 -->
<view class="mask-bottom">
<image src="../static/icon/voice-left.png"></image>
</view>
</view>
</view>
......
<style>
.voice-mask{
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
/* display: flex;
flex-direction: column;
justify-content:...点击查看剩余70%
如何将自己从小生活的农村村庄做成3d可漫游的高斯泼溅?
同一个iframe多次write包含three的html为啥报错不显示Failed to execute 'write' on 'Document': Identifier 'scene' has a
软件工程师的工作内容将由敲代码转变成使用ai来解决现实世界的问题?
claude skills如何本地自动剪辑生成视频?
物理ai是2026年的趋势吗?
ai能对老相机拍摄的底片进行修复成彩色照片吗?
PlayCanvas能在浏览器中交互展示4dgs高斯泼溅文件吗?
jpeg xl格式图片有啥优势?
glb三维模型有几种方式可以降低体积大小减少精度?
如何使用python PyTorch自己训练一个迷你版本的本地chatgpt聊天机器人?


