uniapp 鎖定屏幕方向(默認為縱向主屏)
只能在APP端 (Android 支持, iOS 未測)
plus.screen.lockOrientation(); // 設定屏幕鎖定方向
// 縱向 portrait (自適應)
// 縱向-主屏(手機頂部到底部) portrait-primary
// 縱向-次屏(手機底部到頂部) portrait-secondary
// 橫向 landscape (自適應)
// 橫向-主屏(順時針) landscape-primary
// 橫向-次屏(逆時針) landscape-secondary
1 // 媒體查詢觀察者 2 this.mediaQueryOb = uni.createMediaQueryObserver(this) 3 // 檢測媒體查詢內容(界面變化) 4 this.mediaQueryOb.observe({ 5 minWidth: 375, //頁面最小寬度 375px 6 maxWidth: 500 //頁面寬度最大 500px 7 }, matches => { 8 console.log(matches); 9 })
或者
1 landscapeOb = uni.createMediaQueryObserver(this) 2 landscapeOb.observe({ 3 orientation: 'landscape' //屏幕方向為縱向/橫向 portrait/landscape 4 }, matches => { 5 console.log(matches); 6 this.landscape = matches 7 })
停止監聽
1 this.mediaQueryOb.disconnect() //組件銷毀時停止監聽 2 landscapeOb.disconnect()