Commit 458625a9 by Sarkizz

相机添加前后置摄像头类型

parent 38b8ec29
...@@ -9,12 +9,26 @@ ...@@ -9,12 +9,26 @@
import Foundation import Foundation
import UIKit import UIKit
public enum SACameraDeviceType {
case rear
case front
var device: UIImagePickerController.CameraDevice {
switch self {
case .rear:
return .rear
case .front:
return .front
}
}
}
/// Picker类型 /// Picker类型
public enum SAPhotoPickerType { public enum SAPhotoPickerType {
/// 先显示一个actionSheet,选择类型。count是自定义相册的选择图片数量 /// 先显示一个actionSheet,选择类型。count是自定义相册的选择图片数量
case all(count: Int) case all(count: Int)
/// 相机 /// 相机
case camera case camera(_ type: SACameraDeviceType)
/// 系统相册 /// 系统相册
case photo case photo
/// 系统相册 /// 系统相册
...@@ -84,8 +98,8 @@ public class SAPhotoPicker: NSObject { ...@@ -84,8 +98,8 @@ public class SAPhotoPicker: NSObject {
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil) UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
case .photo: case .photo:
self.showImagePicker(.photoLibrary) self.showImagePicker(.photoLibrary)
case .camera: case .camera(let type):
self.showImagePicker(.camera) self.showImagePicker(.camera, device: type.device)
case .savedPhotosAlbum: case .savedPhotosAlbum:
self.showImagePicker(.savedPhotosAlbum) self.showImagePicker(.savedPhotosAlbum)
case .custom(let count): case .custom(let count):
...@@ -95,12 +109,16 @@ public class SAPhotoPicker: NSObject { ...@@ -95,12 +109,16 @@ public class SAPhotoPicker: NSObject {
} }
extension SAPhotoPicker { extension SAPhotoPicker {
private func showImagePicker(_ type: UIImagePickerController.SourceType) { private func showImagePicker(_ type: UIImagePickerController.SourceType,
device: UIImagePickerController.CameraDevice? = nil) {
let vc = UIImagePickerController() let vc = UIImagePickerController()
vc.sourceType = type vc.sourceType = type
vc.delegate = self vc.delegate = self
vc.title = navTitle(with: type) vc.title = navTitle(with: type)
vc.allowsEditing = editable vc.allowsEditing = editable
if let device = device {
vc.cameraDevice = device
}
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil) UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment