Commit 0d0fa55d by Sarkizz

相册添加是否可编辑选项设置

parent c5460107
......@@ -32,6 +32,8 @@ extension SAPhotoPicker.ConfigKey {
public static let cameraTitle = SAPhotoPicker.ConfigKey(rawValue: "SAPhotoPicker.cameraTitle")
public static let libraryTitle = SAPhotoPicker.ConfigKey(rawValue: "SAPhotoPicker.libraryTitle")
public static let albumTitle = SAPhotoPicker.ConfigKey(rawValue: "SAPhotoPicker.albumTitle")
public static let editable = SAPhotoPicker.ConfigKey(rawValue: "SAPhotoPicker.editable")
}
public class SAPhotoPicker: NSObject {
......@@ -40,7 +42,8 @@ public class SAPhotoPicker: NSObject {
var config: [SAPhotoPicker.ConfigKey: Any] = [
.cameraTitle: "拍照",
.libraryTitle: "相册",
.albumTitle: "相册"
.albumTitle: "相册",
.editable: false
]
private var complateBlock: SAPhotoPickerComplateBlock?
......@@ -81,6 +84,7 @@ extension SAPhotoPicker {
vc.sourceType = type
vc.delegate = self
vc.title = navTitle(with: type)
vc.allowsEditing = editable
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
}
......@@ -96,11 +100,22 @@ extension SAPhotoPicker {
return nil
}
}
private var editable: Bool {
return config[.editable] as? Bool ?? false
}
}
extension SAPhotoPicker: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[.originalImage] as? UIImage {
var image: UIImage? {
if editable {
return info[.editedImage] as? UIImage
}
return info[.originalImage] as? UIImage
}
if let image = image {
complateBlock?(image, info[.referenceURL] as? URL, nil)
} else {
complateBlock?(nil, nil, error(code: -1, msg: "获取图片失败"))
......
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