ios - 如何让用户在 UIImagePicker 中的前置摄像头和后置摄像头之间切换?
问题描述
如何让用户在 UIImagePicker 中的前置摄像头和后置摄像头之间切换?
-(void)takePhoto {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;
[self presentModalViewController:imagePickerController animated:YES];
}
解决方案
如有必要,非常乐意删除此内容,只是想提供帮助....
我刚刚尝试了我的 Swift 编写的应用程序,它使用UIImagePickerController
了 2016 年以来我没有接触过的代码。它看起来和你的代码很相似——除了allowsEditing = false
,对你来说意味着editing = NO
。(我还检查了后置摄像头,以确保它不是运行代码的模拟器。)对我来说,它看起来像是UIImagePickerController
自动为用户提供了一种切换到前置摄像头的方法。
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
picker.allowsEditing = false
picker.sourceType = UIImagePickerController.SourceType.camera
picker.cameraCaptureMode = .photo
picker.modalPresentationStyle = .fullScreen
present(picker,
animated: true,
completion: nil)
} else {
noCamera()
}
}
您是否尝试将编辑设置为 NO?
推荐阅读
- javascript - JQuery UI自动完成下拉菜单未显示
- c# - ASP NET MVC 5:有什么方法可以避免/拦截返回浏览器按钮?
- jdbc - 有什么方法可以禁用 Kafka Connect Job 的 table.poll.interval.ms 吗?
- javascript - 在 React Native 的 TabNavigator 中再次按下时滚动到当前选项卡的顶部
- pytorch - 如何使用torch提供的功能优化5层循环?
- python - fabric3 : 尝试运行 fab 命令时输入密码的 Intempestive Login
- opencv - Mac OSX PyQt5 和 cv2 冲突 int qt
- mysql - MySQL事件在删除之前将表数据复制到其他表中
- android - 带有底部导航的 Android 导航组件不会破坏 startDestination 片段
- c# - 无法在继承的用户控件上修改设计上的受保护控件