async hengButton() {
let screenClass: screen.Screen | null = null;
// this.isLand = true
screen.setScreenRotationLocked(false).then(() => {
screen.getAllScreens((err, data) => {
if (err.code) {
console.error('Failed to get all screens. Cause: === ' + JSON
.stringify(err));
return;
}
console.info('Succeeded in getting all screens. Data:===' + JSON.stringify(data));
screenClass = data[0];
screenClass.setOrientation(screen.Orientation.HORIZONTAL, (err) => {
if (err.code) {
console.error('Failed to set the vertical orientation. Code: ===' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the vertical orientation.===')
});
})
})
}
使用方法
引入import screen from '@ohos.screen';
在生命周期aboutToAppear中执行即可
this.hengButton()
标签:v3.2,arkts,console,err,screen,stringify,JSON,横屏,screenClass From: https://www.cnblogs.com/aowu666/p/18031366