收藏
回答

组件样式修改android无效?

键盘弹起,提高消息输入框的高度,android第一次抬起的高度直接到了屏幕顶部,第二次就正常了,ios上一切正常;代码如下:

<view class="bottomBoxstyle="padding-bottom: {{keyBoardHeight}};">


回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-08-12

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2023-08-12
    有用
    回复 3
    • 小佛
      小佛
      2023-08-12
      onShow() {
              let keyBoardHeight = toString(this.data.bottomHeight) + 'px'
              // keyBoardHeight = '0px'
              console.log('onShow keyBoardHeight', keyBoardHeight);
              this.setData({
                  keyBoardHeight //将键盘的高度设置到data中,后续可以通过它来修改定位textarea的bottom,使它弹起或者收起
              })
              wx.onKeyboardHeightChange(res => { //监听键盘高度变化
                  this.keyBoardChange(res.height)
                  console.log('---res.height', res.height);
              })
              this.getReportDetail()
          },
          keyBoardChange(height) {
              var that = this
              //键盘高度改变时调用
              if (this.data.first) { //弹起时第一次的数据是错误的,所以不需要修改keyBoardHeight
                  this.setData({
                      first: false //将first改为false表示不是第一次调用
                  })
              } else {
                  let keyBoardHeight = (height + this.data.bottomHeight) + 'px'
                  // keyBoardHeight = height + 'px'
                  console.log('keyBoardChange keyBoardHeight', keyBoardHeight);
                  this.setData({
                      keyBoardHeight //将键盘的高度设置到data中,后续可以通过它来修改定位textarea的bottom,使它弹起或者收起
                  })
             
                  if (keyBoardHeight === '0px') {
                      this.setData({
                          showTextara: false //键盘高度等于0时,隐藏textarea
                      })
                  }
              }
          },










      <view class="bottomBox" style="padding-bottom: {{keyBoardHeight}};">
      <!-- <view class="bottomBox" style="margin-bottom: {{keyBoardHeight}};"> -->
          <view class="sendCommentBox">
      <textarea class="commentText" value="{{inputComment}}" bindinput="bzInput" wrap="off" maxlength="100" placeholder="小小鼓励,大大的力量" confirm-type="send" disable-default-padding="0"></textarea>
              <view class="cleanBnt" bindtap="clickClean">
                  <image class="commentCancelImg" src="../../images/叉叉.png"></image>
              </view>
          </view>
          <button class="sendBnt" bindtap="clickSend">发送</button>
      </view>






      .bottomBox {
          width: 100%;
          height: 88rpx;
          background-color: white;
          display: flex;
          align-items: center;
          bottom: 0;
          padding-bottom: env(safe-area-inset-bottom);
          position: fixed;
          box-shadow: 0rpx 0rpx 8rpx 0rpx #a5a5a5;
          z-index: 10;
      }
      2023-08-12
      回复
    • 小佛
      小佛
      2023-08-12
      android每次获取的高度keyBoardHeight是一样的,但是第一次键盘弹出bottomBox 直接高度到手机屏幕最上面了,第二次后就都是正常的在键盘上方刚刚好
      2023-08-12
      回复
    • Demons
      Demons
      2023-08-13回复小佛
      你好我这边测试你给的代码无法复现请根据https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html给个代码片段我这边排查
      2023-08-13
      回复
登录 后发表内容