文章目錄
監聽窗口尺寸變化
uni.onWindowResize(CALLBACK)
- 如App端設置軟鍵盤彈出方式爲adjustResize ,則在鍵盤彈出時,會觸發此事件。
- 橫豎屏切換時,會觸發此事件。
uni.onWindowResize((res) => {
console.log('變化後的窗口寬度=' + res.size.windowWidth)
console.log('變化後的窗口高度=' + res.size.windowHeight)
})
uni.offWindowResize(CALLBACK)
uni.offWindowResize(() => {
console.log('取消監聽窗口尺寸變化事件')
})
隱藏軟鍵盤
uni.hideKeyboard()
隱藏已經顯示的軟鍵盤,如果軟鍵盤沒有顯示則不做任何操作。
uni.onKeyboardHeightChange(CALLBACK)
//監聽鍵盤高度變化
uni.onKeyboardHeightChange(res => {
console.log(res.height)
})