首页 > 解决方案 > 如何让用户在 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];
 }

标签: iosobjective-ccocoa-touch

解决方案


如有必要,非常乐意删除此内容,只是想提供帮助....

我刚刚尝试了我的 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?


推荐阅读