HarmonyOS 横竖屏翻转卡顿

let context =  getContext(this)
this.orientation  = orientation
let windowClass: window.Window | undefined = undefined;
try {
  window.getLastWindow(context, (err: BusinessError, data) => {
    const errCode: number = err.code;
    if (errCode) {
      console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
      return;
    }
    windowClass = data;
    console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));

    try {
      windowClass.setPreferredOrientation(orientation, (err: BusinessError) => {
        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}`);
} 

像这样调用屏幕翻转有时候会卡顿这种怎么处理?

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

可参考以下demo:

import { window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  orientation: window.Orientation = window.Orientation.UNSPECIFIED;
  @State message: string = 'Hello World';

  build() {
    Column() {
      Button("测试").onClick(()=>{
        this.buildOnc()
      })
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
    }
    .height('100%')
    .width('100%')
  }

  buildOnc(){
    let context = getContext(this);
    this.orientation =this.orientation==  window.Orientation.PORTRAIT?window.Orientation.LANDSCAPE:window.Orientation.PORTRAIT;
    let windowClass: window.Window | undefined = undefined;
    try {
      window.getLastWindow(context, (err: BusinessError, data) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
          return;
        }
        windowClass = data;
        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
        try {
          windowClass.setPreferredOrientation(this.orientation, (err: BusinessError) => {
            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}`);
    }
  }
}

在横竖屏切换的时候会有个黑色背景,这个算规格。

分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS 页面滑动
228浏览 • 1回复 待解决
HarmonyOS List嵌套waterflow滑动
456浏览 • 1回复 待解决
HarmonyOS 页面嵌套滑动时
21浏览 • 1回复 待解决
HarmonyOS 横竖切换
213浏览 • 1回复 待解决
HarmonyOS 横竖切换问题
241浏览 • 1回复 待解决
HarmonyOS 横竖设置问题
104浏览 • 1回复 待解决
HarmonyOS LazyForEach多层级数据性能
195浏览 • 1回复 待解决
HarmonyOS WebView加载H5
259浏览 • 1回复 待解决
HarmonyOS 设置横竖问题
100浏览 • 1回复 待解决
HarmonyOS 监听横竖切换
206浏览 • 1回复 待解决
关于启动慢问题首帧分析
585浏览 • 1回复 待解决
Web嵌套滑动怎么办?
366浏览 • 1回复 待解决
HarmonyOS entry组件的横竖
106浏览 • 1回复 待解决
HarmonyOS 横竖切换实现过于繁琐
244浏览 • 1回复 待解决
HarmonyOS 平板无法正确横竖切换
170浏览 • 1回复 待解决
自定义组件,怎么办啊?
479浏览 • 1回复 待解决
HarmonyOS 手机系统升级后ui变得
45浏览 • 1回复 待解决