# 如何监听屏幕旋转

可以使用媒体查询接口监听屏幕旋转。参考代码如下：

```
import { mediaquery, UIContext } from '@kit.ArkUI';
const context = AppStorage.get("context") as UIContext;
let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); // Listen for landscape screen events
function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) {
  if (mediaQueryResult.matches) {
    // do something here
  } else {
    // do something here
  }
}
listener.on('change', onPortrait) // Register callback
listener.off('change', onPortrait) // Unregister callback
```

**参考链接**

@ohos.mediaquery (媒体查询)