HarmonyOS 页面orientation横竖屏切换 (API12+)
Reactnative开发。
入口EntryAbility在module.json5的设置如下,orientation设置了竖屏:
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:layered_image",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:app_icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"orientation": "portrait",
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
现在需要跳转到原生的另一个pages中。目前项目有两个pages,Index.ets,Second.ets。
Second的aboutToAppear如下:
async aboutToAppear() {
const monitor = new SystemNetworkMonitor()
monitor.startMonitoring((netType) => {
this.netType = netType
})
await this.requestPermissions();
const params = router.getParams() as RouteParams; // 类型断言
if (params.pushUrl) { // 使用点表示法访问
this.pushUrl = params.pushUrl;
}
// 设置屏幕为横屏
const windowClass = await window.getLastWindow(this.context);
await windowClass.setPreferredOrientation(window.Orientation.LANDSCAPE);
this.player = createV2TXLivePusher(getContext(), V2TXLiveMode.V2TXLiveModeRTMP);
const videoEncoder = new V2TXLiveVideoEncoderParam(V2TXLiveVideoResolution.V2TXLiveVideoResolution1280x720)
videoEncoder.videoBitrate = 2500
videoEncoder.videoResolutionMode = V2TXLiveVideoResolutionMode.V2TXLiveVideoResolutionModeLandscape
this.player.setVideoQuality(videoEncoder)
this.player.setRenderView(this.viewId);
this.player.setRenderMirror(V2TXLiveMirrorType.V2TXLiveMirrorTypeDisable)
this.player.setRenderFillMode(V2TXLiveFillMode.V2TXLiveFillModeFit)
this.player.setObserver(this.playerObserver);
this.player.startCamera(false)
this.player.startMicrophone()
}
当关闭Second后,返回首页还是横屏,希望首页orientation模式不变如何处理。
1
浏览64 发布于2026-04-02 11:25未知归属地
全部评论
最多点赞
最新发布
最早发布
写回答
所见即所得编辑器, editor1
工具栏
0/50000
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
了解社区公约,与您携手共创和谐专业的开发者社区。





































苏公安网备 32011402010933号