请问,动态设置屏幕横屏,这个鸿蒙next支持吗?之前用的plus.screen.lockOrientation
- 发布:2024-08-05 18:06
- 更新:2024-08-23 14:14
- 阅读:160
分享下 UTS 的代码,上传插件还得实名认证,这都要实名无奈了,需要的自己实现吧
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
import { window } from "@kit.ArkUI";
export function setPreferredOrientation(orientation: number) {
const context: Context = getContext();
try {
window.getLastWindow(context, (err, data) => {
const errCode: number = err.code;
if (errCode) {
console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
return;
}
const windowClass = data;
console.info("Succeeded in obtaining the top window. Data: " + JSON.stringify(data));
try {
windowClass.setPreferredOrientation(orientation, (err) => {
const errCode: number = err.code;
if (errCode) {
console.error(`Failed to set window orientation. Cause code: ${err.code}, message: ${err.message}`);
return;
}
console.info("Succeeded in setting window orientation.");
});
} catch (exception) {
console.error(`Failed to set window orientation. Cause code: ${exception.code}, message: ${exception.message}`);
}
});
} catch (exception) {
console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
}
}
暂时还未支持,可以等待后续更新
-
8***@qq.com (作者)
我尝试使用UTS插件去引用鸿蒙api,https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setpreferredorientation9-1 但是不知道windowStage咋引入,我看文档里是javascript:;从生命周期里拿到的
2024-08-05 19:38
8***@qq.com (作者)
感谢大佬分享!
2024-08-23 14:37