1:Android、ios 同時解決;
2:我們在開發的時候會發現textarea或者input拉起鍵盤的時候整個頁面被頂起了,header也被頂沒了;官方給了:adjustPosition='false'屬性,設置完之后頁面就不會被頂起,但是鍵盤把輸入框擋住了,就很惡心;
3:我的實現思路是,adjustPosition='false' ;用@keyboardheightchange監聽鍵盤的高度;在textarea下面給一個view標簽并且加高度;再通過uni.pageScrollTo 在鍵盤拉起的時候上滑頁面;
上代碼
<!-- 你的其他dom元素 寫多少都可以 --><view><textarea border='none' :adjustPosition='false' placeholder="請輸入200字以內的申請人意見" count maxlength='500' @keyboardheightchange='keyboardheightchange' style="width: 100%;" @blur="hideBorad"></textarea><view :style="{'height':(showKeyNum==1?400:keyboardHeight)+'rpx'}"> </view>
</view>
export default{data() {return { keyboardHeight: 0, // 鍵盤高度showKeyNum: 0,//鍵盤打開的次數}},methods: {keyboardheightchange(e) {this.keyboardHeight = e.detail.height;this.showKeyNum++;setTimeout(() => {uni.pageScrollTo({scrollTop: 2000});}, 200)},hideBorad() {this.showKeyNum = 2;this.keyboardHeight = 0;}}}
1:解釋一下為什么要設置鍵盤打開的次數:是因為keyboardheightchange第一次拉起的時候鍵盤的高度監聽不到,所以當等于1 的時候給了一個默認的高度;
2;?@blur="hideBorad" 為什么要設置這個事件,是因為Android系統下keyboardheightchange關閉的時候不觸發;
3:真的是各種坑等著你跳,大家有好的方法也可以提供過來;謝謝參考!