uniapp tabbar 被软键盘顶起 解决方案

uniapp 官方提供了两个api用于做tabbar显示和隐藏的切换,uni.hideTabBar, uni.showTabBar, 这个可以解决tabbar的显示和隐藏,但是Android手机软件盘右上角的向下箭头,主动关闭软键盘,无法监听。希望有解决方法的朋友告知

另附一个底部fixed定位元素隐藏tabbar的 方法:
uni-app 页面底部fixed定位元素被软键盘顶起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现 uniapp 中输入框在 tabbar 上方,并且跟随软键盘的效果,可以按照以下步骤进行: 1. 在 App.vue 中设置全局的样式: ``` <style> .page { height: 100%; display: flex; flex-direction: column; } .content { flex: 1; overflow-y: auto; padding-bottom: 50px; } .tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 999; } </style> ``` 2. 在需要使用输入框的页面中,添加如下代码: ``` <template> <div class="page"> <div class="content"> <!-- 此处添加页面内容 --> <div style="height: 2000px;"></div> </div> <div class="tabbar"> <!-- 此处添加 tabbar --> </div> <div style="position: fixed;bottom: 0;left: 0;right: 0;"> <input type="text" placeholder="请输入内容" style="height: 50px;width: 100%;margin: 0;padding: 0;border: none;background-color: #f8f8f8;"> </div> </div> </template> ``` 3. 在页面中添加软键盘弹起时的事件监听: ``` onShow() { uni.createSelectorQuery().select('input').boundingClientRect((rect) => { let windowHeight = uni.getSystemInfoSync().windowHeight let inputHeight = rect.height let tabbarHeight = 50 // 假设 tabbar 高度为 50px let contentHeight = windowHeight - inputHeight - tabbarHeight this.setData({ contentHeight }) }).exec() } ``` 4. 在页面中动态设置内容区域的高度: ``` <template> <div class="page"> <div class="content" :style="`height: ${contentHeight}px`"> <!-- 此处添加页面内容 --> <div style="height: 2000px;"></div> </div> <div class="tabbar"> <!-- 此处添加 tabbar --> </div> <div style="position: fixed;bottom: 0;left: 0;right: 0;"> <input type="text" placeholder="请输入内容" style="height: 50px;width: 100%;margin: 0;padding: 0;border: none;background-color: #f8f8f8;"> </div> </div> </template> <script> export default { data() { return { contentHeight: 0 } }, onShow() { uni.createSelectorQuery().select('input').boundingClientRect((rect) => { let windowHeight = uni.getSystemInfoSync().windowHeight let inputHeight = rect.height let tabbarHeight = 50 // 假设 tabbar 高度为 50px let contentHeight = windowHeight - inputHeight - tabbarHeight this.contentHeight = contentHeight }).exec() } } </script> ``` 这样就可以实现 uniapp 中输入框在 tabbar 上方,并且跟随软键盘的效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值