进入微信小程序高亮, 返回退出小程序恢复亮度

onHide 生命周期函数--监听小程序隐藏当小程序从前台进入后台,会触发 onHide

前台、后台定义:当用户点击左上角关闭,或者按了设备 Home 键离开微信,小程序并没有直接销毁,而是进入了后台;当再次进入微信或再次打开小程序,又会从后台进入前台。

只有当小程序进入后台一定时间,或者系统资源占用过高,才会被真正的销毁。

获取当前屏幕亮度    currentBrightness存储下来

var that = this;

wx.getScreenBrightness({

success: function (res) {

console.log('当前屏幕亮度指数-------', res.value)

that.setData({

currentBrightness: res.value

});

}

});

//执行高亮操作

wx.setScreenBrightness({

value: 0.8

})

onHide: function () {

//页面隐藏

/// 恢复之前屏幕亮度

wx.setScreenBrightness({

value: this.data.currentBrightness

})

},

你可能感兴趣的:(进入微信小程序高亮, 返回退出小程序恢复亮度)