Commit 458625a9 by Sarkizz

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

parent 38b8ec29
......@@ -9,12 +9,26 @@
import Foundation
import UIKit
public enum SACameraDeviceType {
case rear
case front
var device: UIImagePickerController.CameraDevice {
switch self {
case .rear:
return .rear
case .front:
return .front
}
}
}
/// Picker类型
public enum SAPhotoPickerType {
/// 先显示一个actionSheet,选择类型。count是自定义相册的选择图片数量
case all(count: Int)
/// 相机
case camera
case camera(_ type: SACameraDeviceType)
/// 系统相册
case photo
/// 系统相册
......@@ -84,8 +98,8 @@ public class SAPhotoPicker: NSObject {
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
case .photo:
self.showImagePicker(.photoLibrary)
case .camera:
self.showImagePicker(.camera)
case .camera(let type):
self.showImagePicker(.camera, device: type.device)
case .savedPhotosAlbum:
self.showImagePicker(.savedPhotosAlbum)
case .custom(let count):
......@@ -95,12 +109,16 @@ public class SAPhotoPicker: NSObject {
}
extension SAPhotoPicker {
private func showImagePicker(_ type: UIImagePickerController.SourceType) {
private func showImagePicker(_ type: UIImagePickerController.SourceType,
device: UIImagePickerController.CameraDevice? = nil) {
let vc = UIImagePickerController()
vc.sourceType = type
vc.delegate = self
vc.title = navTitle(with: type)
vc.allowsEditing = editable
if let device = device {
vc.cameraDevice = device
}
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