鸿蒙开发中如何监听屏幕横竖屏变化?

Viewed 62

鸿蒙开发中如何监听屏幕横竖屏变化?.

1 Answers

使用 mediaquery.matchMediaSync('(orientation: portrait)');

具体来说:

private portraitListener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync('(orientation: portrait)');


this.portraitListener.on('change', (result)=> {
      AppStorage.setOrCreate(ScreenUtil.isPortraitKey, result.matches)
    })