用tabbar导航到相机显示页面切回到别的页面相机不关闭:
“tabBar”: {
“color”: “#a9b7b7”,
“selectedColor”: “#11cd6e”,
“borderStyle”: “white”,
“list”: [
{
“selectedIconPath”: “images/index1.png”,
“iconPath”: “images/index.png”,
“pagePath”: “pages/index/index”,
“text”: “首页”
},
{
“selectedIconPath”: “images/phone1.png”,
“iconPath”: “images/phone.png”,
“pagePath”: “pages/phone/phone”,
“text”: “电话”
},
{
“selectedIconPath”: “images/map1.png”,
“iconPath”: “images/map.png”,
“pagePath”: “pages/map/map”,
“text”: “地图”
},
{
“selectedIconPath”: “images/camera1.png”,
“iconPath”: “images/camera.png”,
“pagePath”: “pages/camera/camera”,
“text”: “相机”
}
]
// pages/camera/camera.js
Page({
/**
* 页面的初始数据
*/
data: {
dp: “back”
},
/**
* 生命周期函数–监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数–监听页面初次渲染完成
*/
onReady: function () {
if (wx.createCameraContext()) {
this.cameraContext = wx.createCameraContext(‘myCamera’)
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: ‘提示’,
content: ‘当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。’
})
}
},
/**
* 生命周期函数–监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数–监听页面隐藏
*/
onHide: function () {
console.log(“hide”);
wx.stopRecord();
},
/**
* 生命周期函数–监听页面卸载
*/
onUnload: function () {
console.log(“unload”);
},
/**
* 页面相关事件处理函数–监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
takePhoto() {
this.cameraContext.takePhoto({
quality: ‘high’,
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
})
},
error(e) {
console.log(e.detail)
},
takeBack() {
var dp1 = this.data.dp;
if (this.data.dp == “back”) {
dp1 = “front”;
} else {
dp1 = “back”;
}
this.setData({
dp: dp1
});
}
})