html52.com
我爱小程序-开发者交流社区

用tabbar导航到相机显示页面切回到别的页面相机不关闭

问题模块 框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
客户端 小程序 Bug iOS ios11.2 iphone6s 6.6.6

用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

});


}

})



网友回复

叶蜂:

好的,多谢了,哥们儿

马晓强:

我之前也遇到这个问题了,调用<camera>组件相机就不会关闭,我的解决方案是:

<camera wx-if='{{false}}'> 在不用相机的时候就不加载camera组件,你在跳转之前将参数设为false试试

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付