我正在React Native中使用Expo Camera。我想在轻按“相机”视图时拍摄照片。我该怎么做?
我曾尝试将TouchableOpacity放置在相机标签内,但是当我尝试登录控制台时,用户点击相机视图就没有反应
<Camera style={{ height: '100%', width: '100%', display: this.state.camera }} type={this.state.type} autoFocus={'on'} ratio={'4:3'} focusDepth={0} ref={(ref) => { this.camera = ref }}>
<TouchableOpacity style={{width:'100%', height:'100%'}} onPress={()=>console.log("Testing cam")}>
</TouchableOpacity>
</Camera>
当我点击“摄像机视图”时,我希望它在控制台中打印“ Testing Cam”
答案 0 :(得分:1)
您应该将Camera
放在TouchableOpacity
内,而不要反过来:
<TouchableOpacity style={{width:'100%', height:'100%'}} onPress={()=>console.log("Testing cam")}>
<Camera style={{ height: '100%', width: '100%', display: this.state.camera }} type={this.state.type} autoFocus={'on'} ratio={'4:3'} focusDepth={0} ref={(ref) => { this.camera = ref }}>
</Camera
</TouchableOpacity>