应用设置屏幕自动旋转:在模块配置文件module.json5中给EntryAbility设置"orientation": “auto\_rotation\_restricted”,再打开手机自动旋转即可。使用deviceInfo.deviceType去获取设备类型。Demo:Index.ets:onPageShow() { console.log(deviceInfo.deviceType); //如果设备类型为手机(或判断屏幕大小) if (deviceInfo.deviceType == "phone"){ //将窗口设置为受旋转开关控制的自动旋转 window.getLastWindow(getContext(this),(err,win)=>{ win.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED) }) } }
应用设置屏幕自动旋转:在模块配置文件module.json5中给EntryAbility设置"orientation": “auto\_rotation\_restricted”,再打开手机自动旋转即可。
使用deviceInfo.deviceType去获取设备类型。
Demo:
Index.ets: