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));
  });
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
HarmonyOS
2024-12-24 16:24:19
1206浏览
收藏 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 设置横竖问题
641浏览 • 1回复 待解决
HarmonyOS 横竖切换问题
1172浏览 • 1回复 待解决
OpenHarmony 小型系统如何设置横竖
8881浏览 • 1回复 待解决
HarmonyOS 横竖切换
1150浏览 • 1回复 待解决
HarmonyOS 创建子window后横竖切换问题
1015浏览 • 1回复 待解决
HarmonyOS 监听横竖切换
974浏览 • 1回复 待解决
HarmonyOS entry组件的横竖
487浏览 • 1回复 待解决
HarmonyOS 横竖翻转卡顿
772浏览 • 1回复 待解决
HarmonyOS 怎么监听屏幕横竖旋转?
834浏览 • 1回复 待解决
HarmonyOS 平板无法正确横竖切换
921浏览 • 1回复 待解决
HarmonyOS 横竖切换实现过于繁琐
1011浏览 • 1回复 待解决
横竖旋转demo有哪些?
1601浏览 • 1回复 待解决
HarmonyOS 小窗下如何实现横竖切换
986浏览 • 1回复 待解决
HarmonyOS 手机如何判断当前横竖状态
1378浏览 • 1回复 待解决
求大佬告知如何切换横竖
3074浏览 • 1回复 待解决
如何进行页面横竖切换
2913浏览 • 1回复 待解决