uni-app打包h5頁面ios喚起軟鍵盤踩坑


問題:頁面有很多input框,上面的input輸入框,當虛擬鍵盤出來時沒問題,但是下面的input輸入框,就會出現問題,input輸入框會跑到鍵盤后面。

 

網上一陣百度,找到原因:安卓手機中喚起軟鍵盤時頁面會壓縮webview的高度,窗口會執行resize事件,但ios並不會。網上各種百度,嘗試,都失敗了,在快放棄時,找到一個可行的。直接貼代碼:

 1 <template>
 2     <view class="wrapper" id="wrapper" ref="wrapper">
 3         <scroll-view  
 4             :style="{'height': scrollHeight}"
 5             class="scroll-view"
 6             :scroll-y="true">
 7             <view class="evaluate-type-list">
 8                 <view 
 9                     class="evaluate-type-item" 
10                     v-for="(item, index) in options" 
11                     :key="index">
12                     <view class="item-top">
13                         <view class="title">
14                             {{item.title}} 
15                             <text class="score">({{item.score}})</text>
16                         </view>
17                         <view class="content">{{item.content}}</view>
18                     </view>
19                     <view class="item-bottom"> 
20                         <view class="content">
21                             評價
22                             <input 
23                                 v-model.number="item.evaluateScore"
24                                 class="input" 
25                                 type="number" 
26                                 placeholder="請輸入評價分數" 
27                                 @input="checkScore(item)"
28                                 @focus="focusInput"
29                                 @blur="blurInput"
30                                 placeholder-style='color: #d1d1d1' />
31                         </view>
32                         <view class="err-tip" v-if="item.isErr">{{item.errTip}}</view>
33                     </view>
34                 </view>
35             </view>
36             <button class="btn-submit" @tap="submit">確定</button>
37         </scroll-view>
38     </view>
39 </template>
40 
41 <script>
42     export default {
43         data() {
44             return {
45                 scrollHeight: 'calc(100vh - 20upx)',
46             }
47         },
48         methods: {
49             focusInput() {
50                 // 獲取系統信息
51                 let info = uni.getSystemInfoSync();
52                 if(info.platform === 'ios') {
53                     setTimeout(() => {
54                         let viewInfo = this.$refs.wrapper.$el.getBoundingClientRect();
55                         // 獲取視圖偏移量,重新定位操作欄
56                         this.bottomVal = Math.abs(parseFloat(viewInfo.top))
57                         // 重置編輯區高度
58                         this.scrollHeight =  `calc(100vh - ${98 + this.bottomVal}px )`
59                     }, 500)
60                 }
61             },
62             blurInput() {
63                 this.scrollHeight = 'calc(100vh - 180upx)';
64             },
65             
66         }
67     }
68 </script>
69 
70 <style lang="scss" scoped>
71 </style>

終於解決困擾一個星期的問題。如果對你有幫助,請給個贊,謝謝!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM