8***@qq.com
8***@qq.com
  • 发布:2024-08-05 18:06
  • 更新:2024-08-23 14:14
  • 阅读:160

请问,动态设置屏幕横屏,这个鸿蒙next支持吗?之前用的plus.screen.lockOrientation

分类:鸿蒙Next

请问,动态设置屏幕横屏,这个鸿蒙next支持吗?之前用的plus.screen.lockOrientation

2024-08-05 18:06 负责人:无 分享
已邀请:
i***@163.com

i***@163.com

分享下 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 (作者)

    感谢大佬分享!

    2024-08-23 14:37

DCloud_UNI_yuhe

DCloud_UNI_yuhe

暂时还未支持,可以等待后续更新

  • 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

i***@163.com

i***@163.com

你好,请问解决了吗?能否分享下代码

  • 8***@qq.com (作者)

    没有呢,在等官方支持

    2024-08-19 14:46

要回复问题请先登录注册