中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
页面横竖屏如何进行切换
微信扫码分享
设置方法:setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void,Orientation取值为AUTO_ROTATION,表示传感器自动旋转模式。参考代码如下:
import { BusinessError } from '@kit.BasicServicesKit'; let orientation = window.Orientation.AUTO_ROTATION; try{ windowClass.setPreferredOrientation(orientation, (err) => { if(err.code){ console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting window orientation.'); }); }catch (exception) { console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); }
设置方法:setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void,Orientation取值为AUTO_ROTATION,表示传感器自动旋转模式。参考代码如下: