Commit ac3c7fe5 by Sarkizz

添加count和maxSize

parent a277840e
......@@ -16,6 +16,7 @@ public class SAMutableSelectionAlbum: MRAlbumListViewController {
}
public var maxImageSize: CGSize?
public var didFinish: ((_ vc: SAMutableSelectionAlbum, _ images: [UIImage]) -> Void)?
public var didCancel: ((_ vc: SAMutableSelectionAlbum) -> Void)?
public override func confirm() {
ToastView.loading()
......@@ -35,6 +36,10 @@ public class SAMutableSelectionAlbum: MRAlbumListViewController {
cell.checkbox.isUserInteractionEnabled = false
}
}
public override func cancel() {
didCancel?(self)
}
}
......
......@@ -10,7 +10,7 @@ import Foundation
import UIKit
public enum SAPhotoPickerType {
case all
case all(count: Int)
case camera
case photo
case savedPhotosAlbum
......@@ -44,22 +44,29 @@ public class SAPhotoPicker: NSObject {
.cameraTitle: "拍照",
.libraryTitle: "相册",
.albumTitle: "相册",
//在调用系统相机或者相册的时候才生效
.editable: false
]
private var imageMaxSize: CGSize?
private var complateBlock: SAPhotoPickerComplateBlock?
public func show(_ type: SAPhotoPickerType = .all, from viewController: UIViewController?,
public func show(_ type: SAPhotoPickerType = .all(count: 1),
imageMaxSize: CGSize? = nil,
from viewController: UIViewController?,
complate: SAPhotoPickerComplateBlock?) {
complateBlock = complate
self.imageMaxSize = imageMaxSize
switch type {
case .all:
case .all(let count):
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "拍照", style: .default, handler: { _ in
alert.addAction(UIAlertAction(title: config[.cameraTitle] as? String,
style: .default, handler: { _ in
self.showImagePicker(.camera)
}))
alert.addAction(UIAlertAction(title: "相册", style: .default, handler: { _ in
self.showImagePicker(.photoLibrary)
alert.addAction(UIAlertAction(title: config[.albumTitle] as? String,
style: .default, handler: { _ in
self.showCustomAlbum(count)
}))
alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: { _ in
complate?(nil, nil, nil)
......@@ -96,10 +103,15 @@ extension SAPhotoPicker {
let vc = SAMutableSelectionAlbum()
vc.title = config[.albumTitle] as? String
vc.maxCount = count
vc.maxImageSize = imageMaxSize
vc.didFinish = { vc, images in
self.complateBlock?(images, nil, nil)
vc.dismiss(animated: true)
}
vc.didCancel = { vc in
self.complateBlock?(nil, nil, nil)
vc.dismiss(animated: true)
}
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
}
......@@ -124,10 +136,11 @@ extension SAPhotoPicker {
extension SAPhotoPicker: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
var image: UIImage? {
if editable {
return info[.editedImage] as? UIImage
var img = editable ? info[.editedImage] as? UIImage : info[.originalImage] as? UIImage
if let size = imageMaxSize {
img = img?.thumbImage(size)
}
return info[.originalImage] as? UIImage
return img
}
if let image = image {
......
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