ums/device/screen
模块引用方式:let screenModule = weex.requireModule(“ums/device/screen”) 该模块包含的api如下:
info(callback)
获取屏幕基本信息
入参说明
回调结果
调用示例
screenModule.info( ret => {
// 成功回调
console.log('取得 screen info = '
+ JSON.stringify(ret))
});
参数详解
属性 | 说明 |
---|---|
dpiX | Number类型;X轴的dip; |
dpiY | Number类型;Y轴的dip; |
height | Number类型;屏幕实际高度 |
width | Number类型;屏幕实际宽度 |
scale | Number类型;屏幕维度 |
setBrightness(brightness, callback)
设置屏幕亮度
入参说明
属性 | 说明 |
---|---|
brightness | Number类型,要设置的屏幕亮度。不允许是””或null。 |
Callback | 回调函数 |
调用示例
screenModule.setBrightness( ‘50’, ret => {
// 成功回调
console.log(设置后的亮度= ' + ret.brightness)
});
参数详解
属性 | 说明 |
---|---|
ret.brightness | 表示设置后的屏幕亮度 |
screenModule.getBrightness(callback)
获取屏幕亮度
入参说明
回调函数
调用示例
screenModule.getBrightness( ret => {
// 成功回调
console.log(取得的亮度= ' + ret.brightness)
});
参数详解
属性 | 说明 |
---|---|
ret.brightness | 表示当前屏幕亮度 |
screenModule.getOrientation(callback)
获取屏幕方向
入参说明
回调函数
调用示例
screenModule.getOrientation( ret => {
// 成功回调
console.log(取得屏幕方向= ' + ret.orientation)
});
参数详解
属性 | 说明 |
---|---|
ret.orientation | 表示当前屏幕方向 |
screenModule.lockOrientation(orientation,callback)
锁定屏幕,不允许旋转
入参说明
属性 | 说明 |
---|---|
orientation | String类型,”landscape”或” portrait” |
回调函数
调用示例
screenModule.lockOrientation(‘landscape’,ret => {
// 成功回调
console.log(取得屏幕方向= ' + ret. orientation)
});
参数详解
属性 | 说明 |
---|---|
ret.orientation | 表示当前屏幕方向 |
screenModule.unlockOrientation(callback)
解除屏幕锁定
入参说明
回调函数
调用示例
screenModule.unlockOrientation(ret => {
// 成功回调
console.log(取得屏幕方向= ' + ret. orientation)
});
参数详解
属性 | 说明 |
---|---|
ret.orientation | 表示当前屏幕方向 |
screenModule.isLandscape()
是否横屏
入参说明
无
调用示例
let result = screenModule.isLandscape()
返回说明
TIP
result=true当前为横屏状态
TIP
result=false当前为竖屏状态