Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
0.1.1
  • Loading branch information
smalltalk committed Apr 26, 2020
1 parent 2b6ca17 commit 13f5ccd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
1 change: 1 addition & 0 deletions Example/WTSimbaImagePickerSwift/OCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (IBAction)pickerButtonPressed:(id)sender {

[self presentViewController:picker animated:YES completion:nil];

// WTSimbaImageAssistant image
}

#pragma mark - -- WTSimbaImagePickerControllerDelegate --
Expand Down
2 changes: 2 additions & 0 deletions Example/WTSimbaImagePickerSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ViewController: UIViewController {
//
// }



}

@objc private func clickBtnPressed() {
Expand Down
2 changes: 1 addition & 1 deletion WTSimbaImagePickerSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'WTSimbaImagePickerSwift'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'A short description of WTSimbaImagePickerSwift.'

# This description is used to generate tags and improve search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ open class WTSimbaImagePickerViewModel: NSObject {

open class WTSimbaImagePickerImageEditedModel: NSObject {

var imagePath = ""
var image: UIImage? = nil
open var imagePath = ""
open var image: UIImage? = nil

func getImageCache() -> UIImage? {
open func getImageCache() -> UIImage? {

return nil
}
Expand Down
69 changes: 45 additions & 24 deletions WTSimbaImagePickerSwift/Classes/Utils/WTSimbaImageAssistant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ open class WTSimbaImageAssistant: NSObject {

}

class func collections(ignoreEmpty: Bool = false, mediaType: WTSimbaImagePickerMediaTypes = .all) -> [PHAssetCollection] {
open class func collectionsDefaut() -> [PHAssetCollection] {
return WTSimbaImageAssistant.collections()
}

open class func collections(ignoreEmpty: Bool = false, mediaType: WTSimbaImagePickerMediaTypes = .all) -> [PHAssetCollection] {
var collections = [PHAssetCollection]()

let userAlbumsOptions = PHFetchOptions()
Expand Down Expand Up @@ -99,7 +103,7 @@ open class WTSimbaImageAssistant: NSObject {
return collections
}

class func assets(from collection: PHAssetCollection, mediaType: WTSimbaImagePickerMediaTypes = .all) -> [PHAsset] {
open class func assets(from collection: PHAssetCollection, mediaType: WTSimbaImagePickerMediaTypes = .all) -> [PHAsset] {
var assets = [PHAsset]()

let fetchOptions = PHFetchOptions()
Expand All @@ -121,7 +125,8 @@ open class WTSimbaImageAssistant: NSObject {
return assets
}

class func firstAssets(from collection: PHAssetCollection) -> PHAsset? {

open class func firstAssets(from collection: PHAssetCollection) -> PHAsset? {

let fetchOptions = PHFetchOptions()
let assetsResult = PHAsset.fetchAssets(in: collection, options: fetchOptions)
Expand All @@ -135,16 +140,16 @@ open class WTSimbaImageAssistant: NSObject {

// MARK: - Attach Start

extension WTSimbaImageAssistant {
public extension WTSimbaImageAssistant {

@available(iOS 8, *)
open class func authorizationStatus() -> PHAuthorizationStatus {
class func authorizationStatus() -> PHAuthorizationStatus {

return PHPhotoLibrary.authorizationStatus()
}

@available(iOS 8, *)
open class func authorizationStatusRequestIfNotDetermined(_ handler: @escaping (PHAuthorizationStatus) -> Void) -> PHAuthorizationStatus{
class func authorizationStatusRequestIfNotDetermined(_ handler: @escaping (PHAuthorizationStatus) -> Void) -> PHAuthorizationStatus{

let status = PHPhotoLibrary.authorizationStatus()
if status == .notDetermined {
Expand All @@ -157,6 +162,40 @@ extension WTSimbaImageAssistant {
return status
}

class func image(asset: PHAsset, resultHandler: @escaping (UIImage?) -> Void, sizeMode: WTSimbaAssetImageSizeMode = .fullResolution, thumbnailSize: CGSize = CGSize(width: 100, height: 100)) {

var targetSize = PHImageManagerMaximumSize
let contentMode: PHImageContentMode = .aspectFit

if sizeMode == .screenSize {
let width = UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height ? UIScreen.main.bounds.size.width : UIScreen.main.bounds.size.height
let height = UIScreen.main.bounds.size.width > UIScreen.main.bounds.size.height ? UIScreen.main.bounds.size.width : UIScreen.main.bounds.size.height
targetSize = CGSize(width: width, height: height)
}else if sizeMode == .thumbnail {
targetSize = thumbnailSize
}

PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: contentMode, options: nil) { (img, _ ) in
resultHandler(img)
}
}

class func imageFullResolution(asset: PHAsset, resultHandler: @escaping (UIImage?) -> Void) {

WTSimbaImageAssistant.image(asset: asset, resultHandler: resultHandler)
}

class func imageScreenSize(asset: PHAsset, thumbnailSize: CGSize, resultHandler: @escaping (UIImage?) -> Void) {

WTSimbaImageAssistant.image(asset: asset, resultHandler: resultHandler, sizeMode: .screenSize)
}

class func imageThumbnail(asset: PHAsset, thumbnailSize: CGSize, resultHandler: @escaping (UIImage?) -> Void) {

WTSimbaImageAssistant.image(asset: asset, resultHandler: resultHandler, sizeMode: .thumbnail, thumbnailSize: thumbnailSize)
}


func saveImage(image: UIImage, album: PHAssetCollection? = nil, completionHandler: ((Bool, PHAsset?, Error?) -> Void)? = nil) {

var assetPlaceholder: PHObjectPlaceholder? = nil
Expand All @@ -180,22 +219,4 @@ extension WTSimbaImageAssistant {
}
}

class func image(asset: PHAsset, resultHandler: @escaping (UIImage?) -> Void, sizeMode: WTSimbaAssetImageSizeMode = .fullResolution, thumbnailSize: CGSize = CGSize(width: 100, height: 100)) {

var targetSize = PHImageManagerMaximumSize
var contentMode: PHImageContentMode = .aspectFit

if sizeMode == .screenSize {
let width = UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height ? UIScreen.main.bounds.size.width : UIScreen.main.bounds.size.height
let height = UIScreen.main.bounds.size.width > UIScreen.main.bounds.size.height ? UIScreen.main.bounds.size.width : UIScreen.main.bounds.size.height
targetSize = CGSize(width: width, height: height)
}else if sizeMode == .thumbnail {
targetSize = thumbnailSize
contentMode = .aspectFill
}

PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: contentMode, options: nil) { (img, _ ) in
resultHandler(img)
}
}
}

0 comments on commit 13f5ccd

Please sign in to comment.