使用如下代码切换横竖屏,横屏状态下视频没有占满。
private screenOrientationChange(isLandscape: boolean) {
this.isLandscape = isLandscape
// 获取UIAbility实例的上下文信息
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
// 调用该接口手动改变设备横竖屏状态
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setPreferredOrientation(this.isLandscape ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT)
});
}
可以在父组件中使用onBackPress,onBackPress当用户点击返回按钮时触发,仅@Entry装饰的自定义组件生效。返回true表示页面自己处理返回逻辑,不进行页面路由;返回false表示使用默认的路由返回逻辑,不设置返回值按照false处理。