step1.获取当前的设备信息
获取当前的设备信息:判断设备类型,是在phone还是ipad,可通过 getsysteminfo deviceType获取。
step2.设置应用支持的横竖屏类型
在manifest.json中进行配置
"screenOrientation": [ //可选,字符串数组类型,应用支持的横竖屏
"portrait-primary", //可选,字符串类型,支持竖屏
"portrait-secondary", //可选,字符串类型,支持反向竖屏
"landscape-primary", //可选,字符串类型,支持横屏
"landscape-secondary" //可选,字符串类型,支持反向横屏
],
step3.设置锁定横竖屏
根据环境 设置锁定横竖屏类型
官方说Android deviceTYpe 的ipad不一定准确,根据需求仅仅发布了移动端,个别用户会在ipad打开,其他环境都没有发布,只需要移动端100%锁成竖屏,其他跟随系统,就能满足基本需求。
app.vue onLaunch中设置
const systemInfo = uni.getSystemInfoSync();
console.log("设备类型",systemInfo.deviceType);
// #ifdef APP-PLUS
if (systemInfo.deviceType === 'phone') {
plus.screen.lockOrientation('portrait-primary'); // 锁定竖屏
}
// #endif