Commit ac3c7fe5 by Sarkizz

添加count和maxSize

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