HarmonyOS 横竖屏设置问题

在调用时设置了横屏window.Orientation.LANDSCAPE没有报错,但是页面却没有旋转横屏。

/**
 * 设置当前设备屏幕方向。
 * @param setOrientation
 */
public static setOrientation(orientation: number) {
  window.getLastWindow(getContext()).then((win) => {
    win.setPreferredOrientation(orientation).then((data) => {
      Logger.debug('setWindowOrientation: ' + orientation + ' Succeeded. Data: ' + JSON.stringify(data));
    }).catch((err: string) => {
      Logger.debug('setWindowOrientation: Failed. Cause: ' + JSON.stringify(err));
    });
  }).catch((err: string) => {
    Logger.debug('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
  });
}
HarmonyOS
2024-12-24 16:24:19
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

建议在module.json5中设置orientation属性值为auto_rotation,应用即具备横竖屏切换能力,若需要横竖屏切换受系统控制(打开自动旋转生效,关闭失效),可以赋值为auto_rotation_restricted 。

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/module-configuration-file-0000001820879553#ZH-CN_TOPIC_0000001811158666__abilities标签

分享
微博
QQ
微信
回复
2024-12-24 19:56:09
相关问题
HarmonyOS 设置横竖问题
160浏览 • 1回复 待解决
HarmonyOS 横竖切换问题
454浏览 • 1回复 待解决
OpenHarmony 小型系统如何设置横竖
8201浏览 • 1回复 待解决
HarmonyOS 横竖切换
402浏览 • 1回复 待解决
HarmonyOS 监听横竖切换
351浏览 • 1回复 待解决
HarmonyOS 横竖切换实现过于繁琐
457浏览 • 1回复 待解决
HarmonyOS 平板无法正确横竖切换
314浏览 • 1回复 待解决
HarmonyOS entry组件的横竖
141浏览 • 1回复 待解决
HarmonyOS 横竖翻转卡顿
171浏览 • 1回复 待解决
页面横竖如何进行切换
758浏览 • 1回复 待解决
如何进行页面横竖切换
2298浏览 • 1回复 待解决
HarmonyOS 怎么监听屏幕横竖旋转?
259浏览 • 1回复 待解决
横竖旋转demo有哪些?
1070浏览 • 1回复 待解决
如何监听设备横竖切换状态呢
1992浏览 • 1回复 待解决
HarmonyOS 小窗下如何实现横竖切换
331浏览 • 1回复 待解决