Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
912d880b
Commit
912d880b
authored
Aug 02, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated PhotoLibrary and UIImage extensions
parent
f7403019
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
145 additions
and
45 deletions
+145
-45
Sources/iOS/Material+UIImage.swift
+8
-8
Sources/iOS/PhotoLibrary.swift
+137
-37
No files found.
Sources/iOS/Material+UIImage.swift
View file @
912d880b
...
@@ -36,7 +36,7 @@ public enum ImageFormat: Int {
...
@@ -36,7 +36,7 @@ public enum ImageFormat: Int {
case
jpeg
case
jpeg
}
}
public
extension
UIImage
{
extension
UIImage
{
/// Width of the UIImage.
/// Width of the UIImage.
public
var
width
:
CGFloat
{
public
var
width
:
CGFloat
{
return
size
.
width
return
size
.
width
...
@@ -48,7 +48,7 @@ public extension UIImage {
...
@@ -48,7 +48,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Resizes an image based on a given width.
Resizes an image based on a given width.
- Parameter toWidth w: A width value.
- Parameter toWidth w: A width value.
...
@@ -94,7 +94,7 @@ public extension UIImage {
...
@@ -94,7 +94,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Creates a new image with the passed in color.
Creates a new image with the passed in color.
- Parameter color: The UIColor to create the image from.
- Parameter color: The UIColor to create the image from.
...
@@ -122,7 +122,7 @@ public extension UIImage {
...
@@ -122,7 +122,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Creates an Image that is a color.
Creates an Image that is a color.
- Parameter color: The UIColor to create the image from.
- Parameter color: The UIColor to create the image from.
...
@@ -140,7 +140,7 @@ public extension UIImage {
...
@@ -140,7 +140,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Crops an image to a specified width and height.
Crops an image to a specified width and height.
- Parameter toWidth tw: A specified width.
- Parameter toWidth tw: A specified width.
...
@@ -165,7 +165,7 @@ public extension UIImage {
...
@@ -165,7 +165,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Creates an clear image.
Creates an clear image.
- Returns: A UIImage that is clear.
- Returns: A UIImage that is clear.
...
@@ -178,7 +178,7 @@ public extension UIImage {
...
@@ -178,7 +178,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Asynchronously load images with a completion block.
Asynchronously load images with a completion block.
- Parameter URL: A URL destination to fetch the image from.
- Parameter URL: A URL destination to fetch the image from.
...
@@ -198,7 +198,7 @@ public extension UIImage {
...
@@ -198,7 +198,7 @@ public extension UIImage {
}
}
}
}
public
extension
UIImage
{
extension
UIImage
{
/**
/**
Adjusts the orientation of the image from the capture orientation.
Adjusts the orientation of the image from the capture orientation.
This is an issue when taking images, the capture orientation is not set correctly
This is an issue when taking images, the capture orientation is not set correctly
...
...
Sources/iOS/PhotoLibrary.swift
View file @
912d880b
...
@@ -232,7 +232,7 @@ public class PhotoLibrary: NSObject {
...
@@ -232,7 +232,7 @@ public class PhotoLibrary: NSObject {
enum that describes the response for the authorization request.
enum that describes the response for the authorization request.
*/
*/
public
func
requestAuthorization
(
_
completion
:
((
PHAuthorizationStatus
)
->
Void
)?
=
nil
)
{
public
func
requestAuthorization
(
_
completion
:
((
PHAuthorizationStatus
)
->
Void
)?
=
nil
)
{
PHPhotoLibrary
.
requestAuthorization
{
[
weak
self
]
(
status
)
in
PHPhotoLibrary
.
requestAuthorization
{
[
weak
self
,
completion
=
completion
]
(
status
)
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
}
}
...
@@ -262,13 +262,12 @@ public class PhotoLibrary: NSObject {
...
@@ -262,13 +262,12 @@ public class PhotoLibrary: NSObject {
}
}
/**
/**
Fetch different PHAssetCollections asynchronously based on different types and subtypes
Fetch all the PHAssetCollections asynchronously based on a type and subtype.
with an optional completion block.
- Parameter type: A PHAssetCollectionType.
- Parameter type: A PHAssetCollectionType.
- Parameter subtype: A PHAssetCollectionSubtype.
- Parameter subtype: A PHAssetCollectionSubtype.
- Parameter completion: A
n optional
completion block.
- Parameter completion: A completion block.
*/
*/
public
func
fetch
(
type
:
PHAssetCollectionType
,
subtype
:
PHAssetCollectionSubtype
,
completion
:
([
PhotoLibraryDataSource
])
->
Void
)
{
public
func
fetch
AssetCollections
(
with
type
:
PHAssetCollectionType
,
subtype
:
PHAssetCollectionSubtype
,
completion
:
([
PhotoLibraryDataSource
])
->
Void
)
{
self
.
type
=
type
self
.
type
=
type
self
.
subtype
=
subtype
self
.
subtype
=
subtype
...
@@ -279,6 +278,9 @@ public class PhotoLibrary: NSObject {
...
@@ -279,6 +278,9 @@ public class PhotoLibrary: NSObject {
defer
{
defer
{
DispatchQueue
.
main
.
async
{
[
weak
self
]
in
DispatchQueue
.
main
.
async
{
[
weak
self
]
in
guard
let
s
=
self
else
{
return
}
completion
(
s
.
collections
)
completion
(
s
.
collections
)
}
}
}
}
...
@@ -302,14 +304,55 @@ public class PhotoLibrary: NSObject {
...
@@ -302,14 +304,55 @@ public class PhotoLibrary: NSObject {
options
.
includeAllBurstAssets
=
true
options
.
includeAllBurstAssets
=
true
options
.
wantsIncrementalChangeDetails
=
true
options
.
wantsIncrementalChangeDetails
=
true
s
.
fetchAssets
(
in
:
collection
,
options
:
options
)
{
[
weak
self
]
(
assets
,
fetchResult
)
in
guard
let
s
=
self
else
{
return
}
s
.
collections
.
append
(
PhotoLibraryDataSource
(
fetchResult
:
fetchResult
,
collection
:
collection
,
assets
:
assets
))
}
}
}
}
/**
Fetch the PHAssets in a given PHAssetCollection.
- Parameter in assetCollection: A PHAssetCollection.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
var
assets
=
[
PHAsset
]()
var
assets
=
[
PHAsset
]()
let
fetchResult
=
PHAsset
.
fetchAssets
(
in
:
collection
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
!
)
}
}
fetchResult
=
PHAsset
.
fetchAssets
(
in
:
assetCollection
,
options
:
options
)
fetchResult
.
enumerateObjects
(
options
:
[])
{
(
asset
,
_
,
_
)
in
fetchResult
.
enumerateObjects
(
options
:
[])
{
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
assets
.
append
(
asset
)
}
}
s
.
collections
.
append
(
PhotoLibraryDataSource
(
fetchResult
:
fetchResult
,
collection
:
collection
,
assets
:
assets
))
}
}
/**
*/
public
func
fetchAssets
(
with
mediaType
:
PHAssetMediaType
,
options
:
PHFetchOptions
?)
->
PHFetchResult
<
PHAsset
>
{
return
PHAsset
.
fetchAssets
(
with
:
mediaType
,
options
:
options
)
}
}
/**
Performes an asynchronous change to the PHPhotoLibrary database.
- Parameter _ block: A transactional block that ensures that
all changes to the PHPhotoLibrary are atomic.
- Parameter completion: A completion block that is executed once the
transaction has been completed.
*/
public
func
performChanges
(
_
block
:
()
->
Void
,
completion
:
((
Bool
,
Error
?)
->
Void
)?
=
nil
)
{
PHPhotoLibrary
.
shared
()
.
performChanges
(
block
,
completionHandler
:
completion
)
}
}
/// A method used to prepare the instance object.
/// A method used to prepare the instance object.
...
@@ -327,32 +370,10 @@ public class PhotoLibrary: NSObject {
...
@@ -327,32 +370,10 @@ public class PhotoLibrary: NSObject {
private
func
prepareChangeObservers
()
{
private
func
prepareChangeObservers
()
{
PHPhotoLibrary
.
shared
()
.
register
(
self
)
PHPhotoLibrary
.
shared
()
.
register
(
self
)
}
}
}
// public func moments(in momentList: PHCollectionList, options: PHFetchOptions?) -> [PHAssetCollection] {
/// PHImageManager.
// var v = [PHAssetCollection]()
extension
PhotoLibrary
{
// PHAssetCollection.fetchMoments(inMomentList: momentList, options: options).enumerateObjects(options: [.concurrent]) { (collection, _, _) in
// v.append(collection)
// }
// return v
// }
//
// public func fetch(with type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, options: PHFetchOptions?) -> PHFetchResult<PHAssetCollection> {
// let result = PHAssetCollection.fetchAssetCollections(with: type, subtype: subtype, options: options)
// return result
// }
//
/**
Performes an asynchronous change to the PHPhotoLibrary database.
- Parameter _ block: A transactional block that ensures that
all changes to the PHPhotoLibrary are atomic.
- Parameter completion: A completion block that is executed once the
transaction has been completed.
*/
public
func
performChanges
(
_
block
:
()
->
Void
,
completion
:
((
Bool
,
Error
?)
->
Void
)?
=
nil
)
{
PHPhotoLibrary
.
shared
()
.
performChanges
(
block
,
completionHandler
:
completion
)
}
/**
/**
Retrieves an optional UIImage for a given PHAsset that allows for a targetSize
Retrieves an optional UIImage for a given PHAsset that allows for a targetSize
and contentMode.
and contentMode.
...
@@ -363,7 +384,7 @@ public class PhotoLibrary: NSObject {
...
@@ -363,7 +384,7 @@ public class PhotoLibrary: NSObject {
- Parameter completion: A completion block.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
- Returns: A PHImageRequestID.
*/
*/
public
func
i
mage
(
for
asset
:
PHAsset
,
targetSize
:
CGSize
,
contentMode
:
PHImageContentMode
,
options
:
PHImageRequestOptions
?,
completion
:
(
UIImage
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
public
func
requestI
mage
(
for
asset
:
PHAsset
,
targetSize
:
CGSize
,
contentMode
:
PHImageContentMode
,
options
:
PHImageRequestOptions
?,
completion
:
(
UIImage
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestImage
(
for
:
asset
,
targetSize
:
targetSize
,
contentMode
:
contentMode
,
options
:
options
,
resultHandler
:
completion
)
return
PHImageManager
.
default
()
.
requestImage
(
for
:
asset
,
targetSize
:
targetSize
,
contentMode
:
contentMode
,
options
:
options
,
resultHandler
:
completion
)
}
}
...
@@ -374,17 +395,96 @@ public class PhotoLibrary: NSObject {
...
@@ -374,17 +395,96 @@ public class PhotoLibrary: NSObject {
- Parameter completion: A completion block.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
- Returns: A PHImageRequestID.
*/
*/
public
func
d
ata
(
for
asset
:
PHAsset
,
options
:
PHImageRequestOptions
?,
completion
:
(
Data
?,
String
?,
UIImageOrientation
,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
public
func
requestImageD
ata
(
for
asset
:
PHAsset
,
options
:
PHImageRequestOptions
?,
completion
:
(
Data
?,
String
?,
UIImageOrientation
,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestImageData
(
for
:
asset
,
options
:
options
,
resultHandler
:
completion
)
return
PHImageManager
.
default
()
.
requestImageData
(
for
:
asset
,
options
:
options
,
resultHandler
:
completion
)
}
}
/**
/**
Cance
;
s an image request for a given PHImageRequestID.
Cance
l
s an image request for a given PHImageRequestID.
- Parameter for requestID: A PHImageRequestID.
- Parameter for requestID: A PHImageRequestID.
*/
*/
public
func
cancel
(
for
requestID
:
PHImageRequestID
)
{
public
func
cancel
ImageRequest
(
for
requestID
:
PHImageRequestID
)
{
PHImageManager
.
default
()
.
cancelImageRequest
(
requestID
)
PHImageManager
.
default
()
.
cancelImageRequest
(
requestID
)
}
}
/**
*/
@available(iOS 9.1, *)
public
func
requestLivePhoto
(
for
asset
:
PHAsset
,
targetSize
:
CGSize
,
contentMode
:
PHImageContentMode
,
options
:
PHLivePhotoRequestOptions
?,
completion
:
(
PHLivePhoto
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestLivePhoto
(
for
:
asset
,
targetSize
:
targetSize
,
contentMode
:
contentMode
,
options
:
options
,
resultHandler
:
completion
)
}
/**
*/
public
func
requestPlayerItem
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
completion
:
(
AVPlayerItem
?,
[
NSObject
:
AnyObject
]?)
->
Swift
.
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestPlayerItem
(
forVideo
:
asset
,
options
:
options
,
resultHandler
:
completion
)
}
/**
*/
public
func
requestExportSession
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
exportPreset
:
String
,
completion
:
(
AVAssetExportSession
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestExportSession
(
forVideo
:
asset
,
options
:
options
,
exportPreset
:
exportPreset
,
resultHandler
:
completion
)
}
/**
*/
public
func
requestAVAsset
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
completion
:
(
AVAsset
?,
AVAudioMix
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestAVAsset
(
forVideo
:
asset
,
options
:
options
,
resultHandler
:
completion
)
}
}
/// PHCollection.
extension
PhotoLibrary
{
/**
Fetch PHCollection based on a type and subtype.
- Parameter with type: A PHCollectionListType.
- Parameter subtype: A PHCollectionListSubtype.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public
func
fetchTopLevelUserCollections
(
with
options
:
PHFetchOptions
?,
completion
:
([
PHCollection
],
PHFetchResult
<
PHCollection
>
)
->
Void
)
{
var
collections
=
[
PHCollection
]()
let
fetchResult
=
PHCollection
.
fetchTopLevelUserCollections
(
with
:
nil
)
defer
{
DispatchQueue
.
main
.
async
{
[
collections
=
collections
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
collections
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
(
options
:
[
.
concurrent
])
{
(
collection
,
_
,
_
)
in
collections
.
append
(
collection
)
}
}
}
/// PHCollectionList.
extension
PhotoLibrary
{
/**
Fetch PHCollectionLists based on a type and subtype.
- Parameter with type: A PHCollectionListType.
- Parameter subtype: A PHCollectionListSubtype.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public
func
fetchCollectionList
(
with
type
:
PHCollectionListType
,
subtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
let
fetchResult
=
PHCollectionList
.
fetchCollectionLists
(
with
:
type
,
subtype
:
subtype
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
(
options
:
[
.
concurrent
])
{
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
}
}
}
}
/// PHPhotoLibraryChangeObserver extension.
/// PHPhotoLibraryChangeObserver extension.
...
@@ -409,7 +509,7 @@ extension PhotoLibrary: PHPhotoLibraryChangeObserver {
...
@@ -409,7 +509,7 @@ extension PhotoLibrary: PHPhotoLibraryChangeObserver {
collections
.
removeAll
()
collections
.
removeAll
()
fetch
(
type
:
t
,
subtype
:
st
)
{
[
weak
self
,
oldCollections
=
oldCollections
]
_
in
fetch
AssetCollections
(
with
:
t
,
subtype
:
st
)
{
[
weak
self
,
oldCollections
=
oldCollections
]
_
in
DispatchQueue
.
main
.
async
{
[
weak
self
,
oldCollections
=
oldCollections
]
in
DispatchQueue
.
main
.
async
{
[
weak
self
,
oldCollections
=
oldCollections
]
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment