先看官方屬性
plus.screen.lockOrientation('default'); // 默認橫豎屏切換
plus.screen.lockOrientation('portrait-primary');// 豎屏展示
plus.screen.lockOrientation('landscape-primary'); // 強制橫屏
簡單需求:允許橫豎屏切換
在 page.json增加以下代碼
"globalStyle": {"pageOrientation": "auto" // 屏幕自動切換},
復雜需求:讓某個界面只能橫屏或者豎屏展示,其他界面不影響
A界面(可以切橫豎屏)
onLoad() {// 頁面加載允許橫豎屏展示// #ifdef APP-PLUSplus.screen.lockOrientation('default');// #endif},
B界面(只允許豎屏)
//頁面顯示時切換為橫屏配置onShow() {// #ifdef APP-PLUSuni.showLoading({title: "加載中..."})setTimeout(() => {plus.screen.unlockOrientation();plus.screen.lockOrientation('portrait-primary');uni.hideLoading();}, 200)//#endif},//頁面卸載時切換為默認或者其他屬性onUnload() {// #ifdef APP-PLUSplus.screen.lockOrientation('default');// #endif},