查看: 18|回复: 0

uni-app APP横屏和竖屏

[复制链接]

4

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2012-6-9
发表于 2022-9-23 16:54:00 | 显示全部楼层 |阅读模式

uni-app APP横屏和竖屏

uni-app APP横屏和竖屏

1、APP判断横屏和竖屏

 uni.getSystemInfo({ // 获取系统信息
    success: function (res) {
	    // 屏幕方向数值: HOME键在右, 0 - 竖屏; 90 - 横屏;  HOME'键在左, 180 - 反向竖屏; -90 - 反向横屏;
	   let orientation = plus.navigator.getOrientation();
	   	var webView = null
	   if(orientation == 0){
		   //竖屏做的操作
		   plus.screen.lockOrientation('landscape-primary')
		   // 设置web-view以外的内容
		   let currentWebview = _this.$scope.$getAppWebview()
		   webView = currentWebview.children()[0]
		   webView.setStyle({
		     top: 0,
		     height: res.windowWidth,
		     width: res.windowHeight
		   })
	   }else if(orientation == 90){
		    //横屏做的操作
		    plus.screen.lockOrientation('portrait-primary')
		    // 设置web-view以外的内容
		    let currentWebview = _this.$scope.$getAppWebview()
		    webView = currentWebview.children()[0]
		    webView.setStyle({
		      top: 80,
		      height: res.windowHeight / 1.5238,
		      width: res.windowHeight
		    })
	   }
  	}
 })
   

2、uni-app APP强制竖屏

 plus.screen.lockOrientation( 'portrait-secondary'); // 反向竖屏
 plus.screen.lockOrientation( 'portrait-primary'); // 正常竖屏

3、uni-app APP强制横屏

plus.screen.lockOrientation( 'landscape-secondary');  // 反向横屏
plus.screen.lockOrientation( 'landscape-primary');  // 正常横屏


来源:https://www.cnblogs.com/lifan-fineDay/p/16723324.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部