有点小九九
简单的事情认真做

 uniapp 锁定屏幕方向(默认为纵向主屏)  

 只能在APP端 (Android 支持, iOS 未测)

 plus.screen.lockOrientation(); // 设定屏幕锁定方向

 // 纵向 portrait (自适应)

 // 纵向-主屏(手机顶部到底部) portrait-primary

 // 纵向-次屏(手机底部到顶部) portrait-secondary

 // 横向 landscape (自适应)

 // 横向-主屏(顺时针)  landscape-primary

 // 横向-次屏(逆时针) landscape-secondary

  

1           // 媒体查询观察者
2                 this.mediaQueryOb = uni.createMediaQueryObserver(this)
3                 // 检测媒体查询内容(界面变化)
4                 this.mediaQueryOb.observe({
5                     minWidth: 375, //页面最小宽度 375px
6                     maxWidth: 500 //页面宽度最大 500px
7                 }, matches => {
8                     console.log(matches);
9                 })

  或者

1           landscapeOb = uni.createMediaQueryObserver(this)
2                 landscapeOb.observe({
3                     orientation: 'landscape' //屏幕方向为纵向/横向 portrait/landscape
4                 }, matches => {
5                     console.log(matches);
6                     this.landscape = matches
7                 })

  停止监听

1                 this.mediaQueryOb.disconnect() //组件销毁时停止监听
2                 landscapeOb.disconnect()

 

  文档链接 

posted on 2021-11-19 15:33  有点小九九  阅读(4043)  评论(0编辑  收藏  举报