Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-syan-image-picker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenSource
react-native-syan-image-picker
Commits
81edf1ae
Commit
81edf1ae
authored
Feb 14, 2019
by
Syan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add iOS 视频时间、占位图
parent
4624da7e
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
241 additions
and
320 deletions
+241
-320
index.js
index.js
+2
-1
RNSyanImagePicker.m
ios/RNSyanImagePicker.m
+22
-6
TZAssetCell.h
ios/TZImagePickerController/TZAssetCell.h
+1
-0
TZAssetCell.m
ios/TZImagePickerController/TZAssetCell.m
+30
-45
TZAssetModel.h
ios/TZImagePickerController/TZAssetModel.h
+2
-0
TZImageManager.h
ios/TZImagePickerController/TZImageManager.h
+10
-11
TZImageManager.m
ios/TZImagePickerController/TZImageManager.m
+21
-32
Root.plist
...ickerController/TZImagePickerController.bundle/Root.plist
+61
-0
Localizable.strings
...ImagePickerController.bundle/en.lproj/Localizable.strings
+0
-0
Localizable.strings
...ImagePickerController.bundle/vi.lproj/Localizable.strings
+0
-1
Localizable.strings
...PickerController.bundle/zh-Hans.lproj/Localizable.strings
+0
-0
Localizable.strings
...PickerController.bundle/zh-Hant.lproj/Localizable.strings
+0
-0
TZImagePickerController.h
ios/TZImagePickerController/TZImagePickerController.h
+28
-16
TZImagePickerController.m
ios/TZImagePickerController/TZImagePickerController.m
+10
-11
TZImageRequestOperation.h
ios/TZImagePickerController/TZImageRequestOperation.h
+0
-30
TZImageRequestOperation.m
ios/TZImagePickerController/TZImageRequestOperation.m
+0
-79
TZLocationManager.h
ios/TZImagePickerController/TZLocationManager.h
+1
-1
TZPhotoPickerController.m
ios/TZImagePickerController/TZPhotoPickerController.m
+18
-25
TZPhotoPreviewCell.h
ios/TZImagePickerController/TZPhotoPreviewCell.h
+0
-1
TZPhotoPreviewCell.m
ios/TZImagePickerController/TZPhotoPreviewCell.m
+27
-50
TZPhotoPreviewController.m
ios/TZImagePickerController/TZPhotoPreviewController.m
+4
-7
TZVideoPlayerController.m
ios/TZImagePickerController/TZVideoPlayerController.m
+3
-3
package.json
package.json
+1
-1
No files found.
index.js
View file @
81edf1ae
...
@@ -133,7 +133,8 @@ export default {
...
@@ -133,7 +133,8 @@ export default {
allowPickingGif
:
true
,
allowPickingGif
:
true
,
allowPickingImage
:
false
,
allowPickingImage
:
false
,
allowPickingMultipleVideo
:
true
,
allowPickingMultipleVideo
:
true
,
videoMaximumDuration
:
20
videoMaximumDuration
:
20
,
...
options
};
};
RNSyanImagePicker
.
openVideoPicker
(
optionObj
,
callback
)
RNSyanImagePicker
.
openVideoPicker
(
optionObj
,
callback
)
}
}
...
...
ios/RNSyanImagePicker.m
View file @
81edf1ae
...
@@ -164,6 +164,14 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
...
@@ -164,6 +164,14 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
{
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
{
video
[
@"type"
]
=
@"video"
;
video
[
@"type"
]
=
@"video"
;
}
}
video
[
@"duration"
]
=
@
(
asset
.
duration
);
NSData
*
imageData
=
UIImagePNGRepresentation
(
photos
[
i
]);
NSString
*
fileName
=
[
NSString
stringWithFormat
:
@"%@.png"
,
[[
NSUUID
UUID
]
UUIDString
]];
[
self
createDir
];
NSString
*
filePath
=
[
NSString
stringWithFormat
:
@"%@ImageCaches/%@"
,
NSTemporaryDirectory
(),
fileName
];
if
([
imageData
writeToFile
:
filePath
atomically
:
YES
])
{
video
[
@"coverUri"
]
=
filePath
;
}
[
selectArray
addObject
:
video
];
[
selectArray
addObject
:
video
];
if
(
selectArray
.
count
==
assets
.
count
)
{
if
(
selectArray
.
count
==
assets
.
count
)
{
callback
(@[[
NSNull
null
],
selectArray
]);
callback
(@[[
NSNull
null
],
selectArray
]);
...
@@ -183,16 +191,24 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
...
@@ -183,16 +191,24 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
[
weakPicker
showProgressHUD
];
[
weakPicker
showProgressHUD
];
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
presetName
:
AVAssetExportPreset640x480
success
:^
(
NSString
*
outputPath
)
{
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
presetName
:
AVAssetExportPreset640x480
success
:^
(
NSString
*
outputPath
)
{
NSLog
(
@"视频导出到本地完成,沙盒路径为:%@"
,
outputPath
);
NSLog
(
@"视频导出到本地完成,沙盒路径为:%@"
,
outputPath
);
NSMutableDictionary
*
phot
o
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
vide
o
=
[
NSMutableDictionary
dictionary
];
phot
o
[
@"uri"
]
=
outputPath
;
vide
o
[
@"uri"
]
=
outputPath
;
phot
o
[
@"fileName"
]
=
[
asset
valueForKey
:
@"filename"
];
vide
o
[
@"fileName"
]
=
[
asset
valueForKey
:
@"filename"
];
PHAssetResource
*
resource
=
[[
PHAssetResource
assetResourcesForAsset
:
asset
]
firstObject
];
PHAssetResource
*
resource
=
[[
PHAssetResource
assetResourcesForAsset
:
asset
]
firstObject
];
long
long
size
=
[[
resource
valueForKey
:
@"fileSize"
]
longLongValue
];
long
long
size
=
[[
resource
valueForKey
:
@"fileSize"
]
longLongValue
];
phot
o
[
@"size"
]
=
@
(
size
);
vide
o
[
@"size"
]
=
@
(
size
);
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
{
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
{
photo
[
@"type"
]
=
@"video"
;
video
[
@"type"
]
=
@"video"
;
}
video
[
@"duration"
]
=
@
(
asset
.
duration
);
NSData
*
imageData
=
UIImagePNGRepresentation
(
coverImage
);
NSString
*
fileName
=
[
NSString
stringWithFormat
:
@"%@.png"
,
[[
NSUUID
UUID
]
UUIDString
]];
[
self
createDir
];
NSString
*
filePath
=
[
NSString
stringWithFormat
:
@"%@ImageCaches/%@"
,
NSTemporaryDirectory
(),
fileName
];
if
([
imageData
writeToFile
:
filePath
atomically
:
YES
])
{
video
[
@"coverUri"
]
=
filePath
;
}
}
callback
(@[[
NSNull
null
],
@[
phot
o
]]);
callback
(@[[
NSNull
null
],
@[
vide
o
]]);
[
weakPicker
dismissViewControllerAnimated
:
YES
completion
:
nil
];
[
weakPicker
dismissViewControllerAnimated
:
YES
completion
:
nil
];
[
weakPicker
hideProgressHUD
];
[
weakPicker
hideProgressHUD
];
}
failure
:^
(
NSString
*
errorMessage
,
NSError
*
error
)
{
}
failure
:^
(
NSString
*
errorMessage
,
NSError
*
error
)
{
...
...
ios/TZImagePickerController/TZAssetCell.h
View file @
81edf1ae
...
@@ -35,6 +35,7 @@ typedef enum : NSUInteger {
...
@@ -35,6 +35,7 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
assign
)
BOOL
showSelectBtn
;
@property
(
nonatomic
,
assign
)
BOOL
showSelectBtn
;
@property
(
assign
,
nonatomic
)
BOOL
allowPreview
;
@property
(
assign
,
nonatomic
)
BOOL
allowPreview
;
@property
(
assign
,
nonatomic
)
BOOL
useCachedImage
;
@property
(
nonatomic
,
copy
)
void
(
^
assetCellDidSetModelBlock
)(
TZAssetCell
*
cell
,
UIImageView
*
imageView
,
UIImageView
*
selectImageView
,
UILabel
*
indexLabel
,
UIView
*
bottomView
,
UILabel
*
timeLength
,
UIImageView
*
videoImgView
);
@property
(
nonatomic
,
copy
)
void
(
^
assetCellDidSetModelBlock
)(
TZAssetCell
*
cell
,
UIImageView
*
imageView
,
UIImageView
*
selectImageView
,
UILabel
*
indexLabel
,
UIView
*
bottomView
,
UILabel
*
timeLength
,
UIImageView
*
videoImgView
);
@property
(
nonatomic
,
copy
)
void
(
^
assetCellDidLayoutSubviewsBlock
)(
TZAssetCell
*
cell
,
UIImageView
*
imageView
,
UIImageView
*
selectImageView
,
UILabel
*
indexLabel
,
UIView
*
bottomView
,
UILabel
*
timeLength
,
UIImageView
*
videoImgView
);
@property
(
nonatomic
,
copy
)
void
(
^
assetCellDidLayoutSubviewsBlock
)(
TZAssetCell
*
cell
,
UIImageView
*
imageView
,
UIImageView
*
selectImageView
,
UILabel
*
indexLabel
,
UIView
*
bottomView
,
UILabel
*
timeLength
,
UIImageView
*
videoImgView
);
...
...
ios/TZImagePickerController/TZAssetCell.m
View file @
81edf1ae
...
@@ -28,33 +28,33 @@
...
@@ -28,33 +28,33 @@
@implementation
TZAssetCell
@implementation
TZAssetCell
-
(
instancetype
)
initWithFrame
:(
CGRect
)
frame
{
self
=
[
super
initWithFrame
:
frame
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
reload
:
)
name
:
@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION"
object
:
nil
];
return
self
;
}
-
(
void
)
setModel
:(
TZAssetModel
*
)
model
{
-
(
void
)
setModel
:(
TZAssetModel
*
)
model
{
_model
=
model
;
_model
=
model
;
self
.
representedAssetIdentifier
=
model
.
asset
.
localIdentifier
;
self
.
representedAssetIdentifier
=
model
.
asset
.
localIdentifier
;
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
self
.
useCachedImage
&&
model
.
cachedImage
)
{
// Set the cell's thumbnail image if it's still showing the same asset.
self
.
imageView
.
image
=
model
.
cachedImage
;
if
([
self
.
representedAssetIdentifier
isEqualToString
:
model
.
asset
.
localIdentifier
])
{
}
else
{
self
.
imageView
.
image
=
photo
;
self
.
model
.
cachedImage
=
nil
;
}
else
{
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
// NSLog(@"this cell is showing other asset");
// Set the cell's thumbnail image if it's still showing the same asset.
if
([
self
.
representedAssetIdentifier
isEqualToString
:
model
.
asset
.
localIdentifier
])
{
self
.
imageView
.
image
=
photo
;
self
.
model
.
cachedImage
=
photo
;
}
else
{
// NSLog(@"this cell is showing other asset");
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
}
if
(
!
isDegraded
)
{
[
self
hideProgressView
];
self
.
imageRequestID
=
0
;
}
}
progressHandler
:
nil
networkAccessAllowed
:
NO
];
if
(
imageRequestID
&&
self
.
imageRequestID
&&
imageRequestID
!=
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
}
}
if
(
!
isDegraded
)
{
self
.
imageRequestID
=
imageRequestID
;
[
self
hideProgressView
];
self
.
imageRequestID
=
0
;
}
}
progressHandler
:
nil
networkAccessAllowed
:
NO
];
if
(
imageRequestID
&&
self
.
imageRequestID
&&
imageRequestID
!=
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
}
}
self
.
imageRequestID
=
imageRequestID
;
self
.
selectPhotoButton
.
selected
=
model
.
isSelected
;
self
.
selectPhotoButton
.
selected
=
model
.
isSelected
;
self
.
selectImageView
.
image
=
self
.
selectPhotoButton
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
self
.
selectImageView
.
image
=
self
.
selectPhotoButton
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
self
.
indexLabel
.
hidden
=
!
self
.
selectPhotoButton
.
isSelected
;
self
.
indexLabel
.
hidden
=
!
self
.
selectPhotoButton
.
isSelected
;
...
@@ -73,6 +73,10 @@
...
@@ -73,6 +73,10 @@
}
else
{
}
else
{
[
self
cancelBigImageRequest
];
[
self
cancelBigImageRequest
];
}
}
if
(
model
.
needOscillatoryAnimation
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
self
.
selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
model
.
needOscillatoryAnimation
=
NO
;
[
self
setNeedsLayout
];
[
self
setNeedsLayout
];
if
(
self
.
assetCellDidSetModelBlock
)
{
if
(
self
.
assetCellDidSetModelBlock
)
{
...
@@ -140,7 +144,9 @@
...
@@ -140,7 +144,9 @@
}
}
self
.
selectImageView
.
image
=
sender
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
self
.
selectImageView
.
image
=
sender
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
if
(
sender
.
isSelected
)
{
if
(
sender
.
isSelected
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
if
(
!
[
TZImagePickerConfig
sharedInstance
].
showSelectedIndex
&&
!
[
TZImagePickerConfig
sharedInstance
].
showPhotoCannotSelectLayer
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
// 用户选中了该图片,提前获取一下大图
// 用户选中了该图片,提前获取一下大图
[
self
requestBigImage
];
[
self
requestBigImage
];
}
else
{
// 取消选中,取消大图的获取
}
else
{
// 取消选中,取消大图的获取
...
@@ -179,8 +185,7 @@
...
@@ -179,8 +185,7 @@
[
self
hideProgressView
];
[
self
hideProgressView
];
}
}
}
else
{
}
else
{
// 快速连续点几次,会EXC_BAD_ACCESS...
*
stop
=
YES
;
// *stop = YES;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
self
cancelBigImageRequest
];
[
self
cancelBigImageRequest
];
}
}
...
@@ -194,22 +199,6 @@
...
@@ -194,22 +199,6 @@
[
self
hideProgressView
];
[
self
hideProgressView
];
}
}
#pragma mark - Notification
-
(
void
)
reload
:
(
NSNotification
*
)
noti
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
noti
.
object
;
if
(
self
.
model
.
isSelected
&&
tzImagePickerVc
.
showSelectedIndex
)
{
self
.
index
=
[
tzImagePickerVc
.
selectedAssetIds
indexOfObject
:
self
.
model
.
asset
.
localIdentifier
]
+
1
;
}
self
.
indexLabel
.
hidden
=
!
self
.
selectPhotoButton
.
isSelected
;
if
(
tzImagePickerVc
.
selectedModels
.
count
>=
tzImagePickerVc
.
maxImagesCount
&&
tzImagePickerVc
.
showPhotoCannotSelectLayer
&&
!
self
.
model
.
isSelected
)
{
self
.
cannotSelectLayerButton
.
backgroundColor
=
tzImagePickerVc
.
cannotSelectLayerColor
;
self
.
cannotSelectLayerButton
.
hidden
=
NO
;
}
else
{
self
.
cannotSelectLayerButton
.
hidden
=
YES
;
}
}
#pragma mark - Lazy load
#pragma mark - Lazy load
-
(
UIButton
*
)
selectPhotoButton
{
-
(
UIButton
*
)
selectPhotoButton
{
...
@@ -270,7 +259,7 @@
...
@@ -270,7 +259,7 @@
-
(
UIImageView
*
)
videoImgView
{
-
(
UIImageView
*
)
videoImgView
{
if
(
_videoImgView
==
nil
)
{
if
(
_videoImgView
==
nil
)
{
UIImageView
*
videoImgView
=
[[
UIImageView
alloc
]
init
];
UIImageView
*
videoImgView
=
[[
UIImageView
alloc
]
init
];
[
videoImgView
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"VideoSendIcon"
]];
[
videoImgView
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"VideoSendIcon"
]];
[
self
.
bottomView
addSubview
:
videoImgView
];
[
self
.
bottomView
addSubview
:
videoImgView
];
_videoImgView
=
videoImgView
;
_videoImgView
=
videoImgView
;
}
}
...
@@ -349,10 +338,6 @@
...
@@ -349,10 +338,6 @@
}
}
}
}
-
(
void
)
dealloc
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
}
@end
@end
@interface
TZAlbumCell
()
@interface
TZAlbumCell
()
...
...
ios/TZImagePickerController/TZAssetModel.h
View file @
81edf1ae
...
@@ -23,7 +23,9 @@ typedef enum : NSUInteger {
...
@@ -23,7 +23,9 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
strong
)
PHAsset
*
asset
;
@property
(
nonatomic
,
strong
)
PHAsset
*
asset
;
@property
(
nonatomic
,
assign
)
BOOL
isSelected
;
///< The select status of a photo, default is No
@property
(
nonatomic
,
assign
)
BOOL
isSelected
;
///< The select status of a photo, default is No
@property
(
nonatomic
,
assign
)
TZAssetModelMediaType
type
;
@property
(
nonatomic
,
assign
)
TZAssetModelMediaType
type
;
@property
(
assign
,
nonatomic
)
BOOL
needOscillatoryAnimation
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
strong
,
nonatomic
)
UIImage
*
cachedImage
;
/// Init a photo dataModel With a PHAsset
/// Init a photo dataModel With a PHAsset
/// 用一个PHAsset实例,初始化一个照片模型
/// 用一个PHAsset实例,初始化一个照片模型
...
...
ios/TZImagePickerController/TZImageManager.h
View file @
81edf1ae
...
@@ -58,22 +58,21 @@
...
@@ -58,22 +58,21 @@
-
(
void
)
getAssetFromFetchResult
:(
PHFetchResult
*
)
result
atIndex
:(
NSInteger
)
index
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAssetModel
*
model
))
completion
;
-
(
void
)
getAssetFromFetchResult
:(
PHFetchResult
*
)
result
atIndex
:(
NSInteger
)
index
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAssetModel
*
model
))
completion
;
/// Get photo 获得照片
/// Get photo 获得照片
-
(
PHImageRequestID
)
getPostImageWithAlbumModel
:(
TZAlbumModel
*
)
model
completion
:(
void
(
^
)(
UIImage
*
postImage
))
completion
;
-
(
void
)
getPostImageWithAlbumModel
:(
TZAlbumModel
*
)
model
completion
:(
void
(
^
)(
UIImage
*
postImage
))
completion
;
-
(
PHImageRequestID
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
PHImageRequestID
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
PHImageRequestID
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
PHImageRequestID
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
int32_t
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
photoWidth
:(
CGFloat
)
photoWidth
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:(
BOOL
)
networkAccessAllowed
;
-
(
PHImageRequestID
)
requestImageDataForAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
;
-
(
int32_t
)
requestImageDataForAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
;
/// Get full Image 获取原图
/// Get full Image 获取原图
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
// 该方法中,completion只会走一次
// 该方法中,completion只会走一次
-
(
PHImageRequestID
)
getOriginalPhotoDataWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoDataWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
PHImageRequestID
)
getOriginalPhotoDataWithAsset
:(
PHAsset
*
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoDataWithAsset
:(
PHAsset
*
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
/// Save photo 保存照片
/// Save photo 保存照片
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
...
...
ios/TZImagePickerController/TZImageManager.m
View file @
81edf1ae
...
@@ -142,9 +142,9 @@ static dispatch_once_t onceToken;
...
@@ -142,9 +142,9 @@ static dispatch_once_t onceToken;
// 有可能是PHCollectionList类的的对象,过滤掉
// 有可能是PHCollectionList类的的对象,过滤掉
if
(
!
[
collection
isKindOfClass
:[
PHAssetCollection
class
]])
continue
;
if
(
!
[
collection
isKindOfClass
:[
PHAssetCollection
class
]])
continue
;
// 过滤空相册
// 过滤空相册
if
(
collection
.
estimatedAssetCount
<=
0
&&
!
[
self
isCameraRollAlbum
:
collection
]
)
continue
;
if
(
collection
.
estimatedAssetCount
<=
0
)
continue
;
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
if
(
fetchResult
.
count
<
1
&&
!
[
self
isCameraRollAlbum
:
collection
]
)
continue
;
if
(
fetchResult
.
count
<
1
)
continue
;
if
([
self
.
pickerDelegate
respondsToSelector
:
@selector
(
isAlbumCanSelect
:
result
:
)])
{
if
([
self
.
pickerDelegate
respondsToSelector
:
@selector
(
isAlbumCanSelect
:
result
:
)])
{
if
(
!
[
self
.
pickerDelegate
isAlbumCanSelect
:
collection
.
localizedTitle
result
:
fetchResult
])
{
if
(
!
[
self
.
pickerDelegate
isAlbumCanSelect
:
collection
.
localizedTitle
result
:
fetchResult
])
{
...
@@ -161,9 +161,7 @@ static dispatch_once_t onceToken;
...
@@ -161,9 +161,7 @@ static dispatch_once_t onceToken;
}
}
}
}
}
}
if
(
completion
)
{
if
(
completion
&&
albumArr
.
count
>
0
)
completion
(
albumArr
);
completion
(
albumArr
);
}
}
}
#pragma mark - Get Assets
#pragma mark - Get Assets
...
@@ -303,7 +301,7 @@ static dispatch_once_t onceToken;
...
@@ -303,7 +301,7 @@ static dispatch_once_t onceToken;
#pragma mark - Get Photo
#pragma mark - Get Photo
/// Get photo 获得照片本身
/// Get photo 获得照片本身
-
(
PHImageRequestID
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
,
NSDictionary
*
,
BOOL
isDegraded
))
completion
{
-
(
int32_t
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
,
NSDictionary
*
,
BOOL
isDegraded
))
completion
{
CGFloat
fullScreenWidth
=
TZScreenWidth
;
CGFloat
fullScreenWidth
=
TZScreenWidth
;
if
(
fullScreenWidth
>
_photoPreviewMaxWidth
)
{
if
(
fullScreenWidth
>
_photoPreviewMaxWidth
)
{
fullScreenWidth
=
_photoPreviewMaxWidth
;
fullScreenWidth
=
_photoPreviewMaxWidth
;
...
@@ -311,11 +309,11 @@ static dispatch_once_t onceToken;
...
@@ -311,11 +309,11 @@ static dispatch_once_t onceToken;
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
nil
networkAccessAllowed
:
YES
];
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
nil
networkAccessAllowed
:
YES
];
}
}
-
(
PHImageRequestID
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
photoWidth
:
(
CGFloat
)
photoWidth
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
-
(
int32_t
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
photoWidth
:
(
CGFloat
)
photoWidth
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
photoWidth
completion
:
completion
progressHandler
:
nil
networkAccessAllowed
:
YES
];
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
photoWidth
completion
:
completion
progressHandler
:
nil
networkAccessAllowed
:
YES
];
}
}
-
(
PHImageRequestID
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:
(
BOOL
)
networkAccessAllowed
{
-
(
int32_t
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:
(
BOOL
)
networkAccessAllowed
{
CGFloat
fullScreenWidth
=
TZScreenWidth
;
CGFloat
fullScreenWidth
=
TZScreenWidth
;
if
(
_photoPreviewMaxWidth
>
0
&&
fullScreenWidth
>
_photoPreviewMaxWidth
)
{
if
(
_photoPreviewMaxWidth
>
0
&&
fullScreenWidth
>
_photoPreviewMaxWidth
)
{
fullScreenWidth
=
_photoPreviewMaxWidth
;
fullScreenWidth
=
_photoPreviewMaxWidth
;
...
@@ -323,7 +321,7 @@ static dispatch_once_t onceToken;
...
@@ -323,7 +321,7 @@ static dispatch_once_t onceToken;
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
progressHandler
networkAccessAllowed
:
networkAccessAllowed
];
return
[
self
getPhotoWithAsset
:
asset
photoWidth
:
fullScreenWidth
completion
:
completion
progressHandler
:
progressHandler
networkAccessAllowed
:
networkAccessAllowed
];
}
}
-
(
PHImageRequestID
)
requestImageDataForAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
{
-
(
int32_t
)
requestImageDataForAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
{
PHImageRequestOptions
*
options
=
[[
PHImageRequestOptions
alloc
]
init
];
PHImageRequestOptions
*
options
=
[[
PHImageRequestOptions
alloc
]
init
];
options
.
progressHandler
=
^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
options
.
progressHandler
=
^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
...
@@ -340,14 +338,14 @@ static dispatch_once_t onceToken;
...
@@ -340,14 +338,14 @@ static dispatch_once_t onceToken;
return
imageRequestID
;
return
imageRequestID
;
}
}
-
(
PHImageRequestID
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
photoWidth
:
(
CGFloat
)
photoWidth
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:
(
BOOL
)
networkAccessAllowed
{
-
(
int32_t
)
getPhotoWithAsset
:
(
PHAsset
*
)
asset
photoWidth
:
(
CGFloat
)
photoWidth
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
networkAccessAllowed
:
(
BOOL
)
networkAccessAllowed
{
CGSize
imageSize
;
CGSize
imageSize
;
if
(
photoWidth
<
TZScreenWidth
&&
photoWidth
<
_photoPreviewMaxWidth
)
{
if
(
photoWidth
<
TZScreenWidth
&&
photoWidth
<
_photoPreviewMaxWidth
)
{
imageSize
=
AssetGridThumbnailSize
;
imageSize
=
AssetGridThumbnailSize
;
}
else
{
}
else
{
PHAsset
*
phAsset
=
(
PHAsset
*
)
asset
;
PHAsset
*
phAsset
=
(
PHAsset
*
)
asset
;
CGFloat
aspectRatio
=
phAsset
.
pixelWidth
/
(
CGFloat
)
phAsset
.
pixelHeight
;
CGFloat
aspectRatio
=
phAsset
.
pixelWidth
/
(
CGFloat
)
phAsset
.
pixelHeight
;
CGFloat
pixelWidth
=
photoWidth
*
TZScreenScale
;
CGFloat
pixelWidth
=
photoWidth
*
TZScreenScale
*
1
.
5
;
// 超宽图片
// 超宽图片
if
(
aspectRatio
>
1
.
8
)
{
if
(
aspectRatio
>
1
.
8
)
{
pixelWidth
=
pixelWidth
*
aspectRatio
;
pixelWidth
=
pixelWidth
*
aspectRatio
;
...
@@ -403,37 +401,30 @@ static dispatch_once_t onceToken;
...
@@ -403,37 +401,30 @@ static dispatch_once_t onceToken;
}
}
/// Get postImage / 获取封面图
/// Get postImage / 获取封面图
-
(
PHImageRequestID
)
getPostImageWithAlbumModel
:
(
TZAlbumModel
*
)
model
completion
:
(
void
(
^
)(
UIImage
*
))
completion
{
-
(
void
)
getPostImageWithAlbumModel
:
(
TZAlbumModel
*
)
model
completion
:
(
void
(
^
)(
UIImage
*
))
completion
{
id
asset
=
[
model
.
result
lastObject
];
id
asset
=
[
model
.
result
lastObject
];
if
(
!
self
.
sortAscendingByModificationDate
)
{
if
(
!
self
.
sortAscendingByModificationDate
)
{
asset
=
[
model
.
result
firstObject
];
asset
=
[
model
.
result
firstObject
];
}
}
return
[[
TZImageManager
manager
]
getPhotoWithAsset
:
asset
photoWidth
:
80
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
asset
photoWidth
:
80
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
completion
)
completion
(
photo
);
if
(
completion
)
completion
(
photo
);
}];
}];
}
}
/// Get Original Photo / 获取原图
/// Get Original Photo / 获取原图
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
{
-
(
void
)
getOriginalPhotoWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
{
return
[
self
getOriginalPhotoWithAsset
:
asset
newCompletion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
[
self
getOriginalPhotoWithAsset
:
asset
newCompletion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
completion
)
{
if
(
completion
)
{
completion
(
photo
,
info
);
completion
(
photo
,
info
);
}
}
}];
}];
}
}
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:
(
PHAsset
*
)
asset
newCompletion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
-
(
void
)
getOriginalPhotoWithAsset
:
(
PHAsset
*
)
asset
newCompletion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
return
[
self
getOriginalPhotoWithAsset
:
asset
progressHandler
:
nil
newCompletion
:
completion
];
}
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:
(
PHAsset
*
)
asset
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
newCompletion
:
(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
PHImageRequestOptions
*
option
=
[[
PHImageRequestOptions
alloc
]
init
];
PHImageRequestOptions
*
option
=
[[
PHImageRequestOptions
alloc
]
init
];
option
.
networkAccessAllowed
=
YES
;
option
.
networkAccessAllowed
=
YES
;
if
(
progressHandler
)
{
[
option
setProgressHandler
:
progressHandler
];
}
option
.
resizeMode
=
PHImageRequestOptionsResizeModeFast
;
option
.
resizeMode
=
PHImageRequestOptionsResizeModeFast
;
return
[[
PHImageManager
defaultManager
]
requestImageForAsset
:
asset
targetSize
:
PHImageManagerMaximumSize
contentMode
:
PHImageContentModeAspectFit
options
:
option
resultHandler
:^
(
UIImage
*
result
,
NSDictionary
*
info
)
{
[[
PHImageManager
defaultManager
]
requestImageForAsset
:
asset
targetSize
:
PHImageManagerMaximumSize
contentMode
:
PHImageContentModeAspectFit
options
:
option
resultHandler
:^
(
UIImage
*
result
,
NSDictionary
*
info
)
{
BOOL
downloadFinined
=
(
!
[[
info
objectForKey
:
PHImageCancelledKey
]
boolValue
]
&&
!
[
info
objectForKey
:
PHImageErrorKey
]);
BOOL
downloadFinined
=
(
!
[[
info
objectForKey
:
PHImageCancelledKey
]
boolValue
]
&&
!
[
info
objectForKey
:
PHImageErrorKey
]);
if
(
downloadFinined
&&
result
)
{
if
(
downloadFinined
&&
result
)
{
result
=
[
self
fixOrientation
:
result
];
result
=
[
self
fixOrientation
:
result
];
...
@@ -443,11 +434,11 @@ static dispatch_once_t onceToken;
...
@@ -443,11 +434,11 @@ static dispatch_once_t onceToken;
}];
}];
}
}
-
(
PHImageRequestID
)
getOriginalPhotoDataWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
-
(
void
)
getOriginalPhotoDataWithAsset
:
(
PHAsset
*
)
asset
completion
:
(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
return
[
self
getOriginalPhotoDataWithAsset
:
asset
progressHandler
:
nil
completion
:
completion
];
[
self
getOriginalPhotoDataWithAsset
:
asset
progressHandler
:
nil
completion
:
completion
];
}
}
-
(
PHImageRequestID
)
getOriginalPhotoDataWithAsset
:
(
PHAsset
*
)
asset
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:
(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
-
(
void
)
getOriginalPhotoDataWithAsset
:
(
PHAsset
*
)
asset
progressHandler
:
(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:
(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
{
PHImageRequestOptions
*
option
=
[[
PHImageRequestOptions
alloc
]
init
];
PHImageRequestOptions
*
option
=
[[
PHImageRequestOptions
alloc
]
init
];
option
.
networkAccessAllowed
=
YES
;
option
.
networkAccessAllowed
=
YES
;
if
([[
asset
valueForKey
:
@"filename"
]
hasSuffix
:
@"GIF"
])
{
if
([[
asset
valueForKey
:
@"filename"
]
hasSuffix
:
@"GIF"
])
{
...
@@ -456,7 +447,7 @@ static dispatch_once_t onceToken;
...
@@ -456,7 +447,7 @@ static dispatch_once_t onceToken;
}
}
[
option
setProgressHandler
:
progressHandler
];
[
option
setProgressHandler
:
progressHandler
];
option
.
deliveryMode
=
PHImageRequestOptionsDeliveryModeHighQualityFormat
;
option
.
deliveryMode
=
PHImageRequestOptionsDeliveryModeHighQualityFormat
;
return
[[
PHImageManager
defaultManager
]
requestImageDataForAsset
:
asset
options
:
option
resultHandler
:^
(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
)
{
[[
PHImageManager
defaultManager
]
requestImageDataForAsset
:
asset
options
:
option
resultHandler
:^
(
NSData
*
imageData
,
NSString
*
dataUTI
,
UIImageOrientation
orientation
,
NSDictionary
*
info
)
{
BOOL
downloadFinined
=
(
!
[[
info
objectForKey
:
PHImageCancelledKey
]
boolValue
]
&&
!
[
info
objectForKey
:
PHImageErrorKey
]);
BOOL
downloadFinined
=
(
!
[[
info
objectForKey
:
PHImageCancelledKey
]
boolValue
]
&&
!
[
info
objectForKey
:
PHImageErrorKey
]);
if
(
downloadFinined
&&
imageData
)
{
if
(
downloadFinined
&&
imageData
)
{
if
(
completion
)
completion
(
imageData
,
info
,
NO
);
if
(
completion
)
completion
(
imageData
,
info
,
NO
);
...
@@ -581,12 +572,10 @@ static dispatch_once_t onceToken;
...
@@ -581,12 +572,10 @@ static dispatch_once_t onceToken;
// You can compress the resolution to lower. Or you can support more higher resolution.
// You can compress the resolution to lower. Or you can support more higher resolution.
if
([
presets
containsObject
:
presetName
])
{
if
([
presets
containsObject
:
presetName
])
{
AVAssetExportSession
*
session
=
[[
AVAssetExportSession
alloc
]
initWithAsset
:
videoAsset
presetName
:
presetName
];
AVAssetExportSession
*
session
=
[[
AVAssetExportSession
alloc
]
initWithAsset
:
videoAsset
presetName
:
presetName
];
NSDateFormatter
*
formater
=
[[
NSDateFormatter
alloc
]
init
];
NSDateFormatter
*
formater
=
[[
NSDateFormatter
alloc
]
init
];
[
formater
setDateFormat
:
@"yyyy-MM-dd-HH:mm:ss-SSS"
];
[
formater
setDateFormat
:
@"yyyy-MM-dd-HH:mm:ss-SSS"
];
NSString
*
outputPath
=
[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp/video-%@.mp4"
,
[
formater
stringFromDate
:[
NSDate
date
]]];
NSString
*
outputPath
=
[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp/output-%@.mp4"
,
[
formater
stringFromDate
:[
NSDate
date
]]];
if
(
videoAsset
.
URL
&&
videoAsset
.
URL
.
lastPathComponent
)
{
outputPath
=
[
outputPath
stringByReplacingOccurrencesOfString
:
@".mp4"
withString
:[
NSString
stringWithFormat
:
@"-%@"
,
videoAsset
.
URL
.
lastPathComponent
]];
}
// NSLog(@"video outputPath = %@",outputPath);
// NSLog(@"video outputPath = %@",outputPath);
session
.
outputURL
=
[
NSURL
fileURLWithPath
:
outputPath
];
session
.
outputURL
=
[
NSURL
fileURLWithPath
:
outputPath
];
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/Root.plist
0 → 100755
View file @
81edf1ae
<
?xml
v
e
rsion="
1
.
0
"
e
n
c
o
d
ing="UT
F
-
8
"?
>
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
StringsTable
<
/k
e
y
>
<
string
>
Root
<
/string
>
<
k
e
y
>
PreferenceSpecifiers
<
/k
e
y
>
<
a
rr
a
y
>
<
d
i
c
t
>
<
k
e
y
>
Type
<
/k
e
y
>
<
string
>
PSGroupSpecifier
<
/string
>
<
k
e
y
>
Title
<
/k
e
y
>
<
string
>
Group
<
/string
>
<
/
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
Type
<
/k
e
y
>
<
string
>
PSTextFieldSpecifier
<
/string
>
<
k
e
y
>
Title
<
/k
e
y
>
<
string
>
Name
<
/string
>
<
k
e
y
>
Key
<
/k
e
y
>
<
string
>
name_preference
<
/string
>
<
k
e
y
>
DefaultValue
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
IsSecure
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
KeyboardType
<
/k
e
y
>
<
string
>
Alphabet
<
/string
>
<
k
e
y
>
AutocapitalizationType
<
/k
e
y
>
<
string
>
None
<
/string
>
<
k
e
y
>
AutocorrectionType
<
/k
e
y
>
<
string
>
No
<
/string
>
<
/
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
Type
<
/k
e
y
>
<
string
>
PSToggleSwitchSpecifier
<
/string
>
<
k
e
y
>
Title
<
/k
e
y
>
<
string
>
Enabled
<
/string
>
<
k
e
y
>
Key
<
/k
e
y
>
<
string
>
enabled_preference
<
/string
>
<
k
e
y
>
DefaultValue
<
/k
e
y
>
<
tru
e
/
>
<
/
d
i
c
t
>
<
d
i
c
t
>
<
k
e
y
>
Type
<
/k
e
y
>
<
string
>
PSSliderSpecifier
<
/string
>
<
k
e
y
>
Key
<
/k
e
y
>
<
string
>
slider_preference
<
/string
>
<
k
e
y
>
DefaultValue
<
/k
e
y
>
<
r
ea
l
>
0.5
<
/r
ea
l
>
<
k
e
y
>
MinimumValue
<
/k
e
y
>
<
int
e
g
e
r
>
0
<
/int
e
g
e
r
>
<
k
e
y
>
MaximumValue
<
/k
e
y
>
<
int
e
g
e
r
>
1
<
/int
e
g
e
r
>
<
k
e
y
>
MinimumValueImage
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
MaximumValueImage
<
/k
e
y
>
<
string
><
/string
>
<
/
d
i
c
t
>
<
/
a
rr
a
y
>
<
/
d
i
c
t
>
<
/plist
>
ios/TZImagePickerController/TZImagePickerController.bundle/en.lproj/Localizable.strings
View file @
81edf1ae
B
"OK" = "OK";
B
"OK" = "OK";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/vi.lproj/Localizable.strings
View file @
81edf1ae
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
"Preview" = "Xem trước";
"Preview" = "Xem trước";
"Full image" = "Hình gốc";
"Full image" = "Hình gốc";
"Processing..." = "Đang xử lý...";
"Processing..." = "Đang xử lý...";
"No Photos or Videos" = "Không có ảnh hoặc video";
"Can not use camera" = "Máy chụp hình không khả dụng";
"Can not use camera" = "Máy chụp hình không khả dụng";
"Synchronizing photos from iCloud" = "Đang đồng bộ hình ảnh từ ICloud";
"Synchronizing photos from iCloud" = "Đang đồng bộ hình ảnh từ ICloud";
"Can not choose both video and photo" = "Trong lúc chọn hình ảnh không cùng lúc chọn video";
"Can not choose both video and photo" = "Trong lúc chọn hình ảnh không cùng lúc chọn video";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/zh-Hans.lproj/Localizable.strings
View file @
81edf1ae
B
"OK" = "确定";
B
"OK" = "确定";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/zh-Hant.lproj/Localizable.strings
View file @
81edf1ae
B
"OK" = "確定";
B
"OK" = "確定";
...
...
ios/TZImagePickerController/TZImagePickerController.h
View file @
81edf1ae
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
//
//
// Created by 谭真 on 15/12/24.
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// Copyright © 2015年 谭真. All rights reserved.
// version 3.
1.9 - 2019.01.14
// version 3.
0.9 - 2018.10.09
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
/*
/*
...
@@ -127,8 +127,8 @@
...
@@ -127,8 +127,8 @@
/// Default is white color with 0.8 alpha;
/// Default is white color with 0.8 alpha;
@property
(
strong
,
nonatomic
)
UIColor
*
cannotSelectLayerColor
;
@property
(
strong
,
nonatomic
)
UIColor
*
cannotSelectLayerColor
;
/// Default is
YES, if set NO, the result photo will
be scaled to photoWidth pixel width. The photoWidth default is 828px
/// Default is
No, if set YES, the result photo will not
be scaled to photoWidth pixel width. The photoWidth default is 828px
/// 默认是
YES,如果设置为NO,内部
会缩放图片到photoWidth像素宽
/// 默认是
NO,如果设置为YES,内部不
会缩放图片到photoWidth像素宽
@property
(
assign
,
nonatomic
)
BOOL
notScaleImage
;
@property
(
assign
,
nonatomic
)
BOOL
notScaleImage
;
/// 默认是NO,如果设置为YES,导出视频时会修正转向(慎重设为YES,可能导致部分安卓下拍的视频导出失败)
/// 默认是NO,如果设置为YES,导出视频时会修正转向(慎重设为YES,可能导致部分安卓下拍的视频导出失败)
...
@@ -230,11 +230,26 @@
...
@@ -230,11 +230,26 @@
#pragma mark -
#pragma mark -
-
(
void
)
cancelButtonClick
;
-
(
void
)
cancelButtonClick
;
// For method annotations, see the corresponding method in TZImagePickerControllerDelegate / 方法注释见TZImagePickerControllerDelegate中对应方法
// The picker should dismiss itself; when it dismissed these handle will be called.
// You can also set autoDismiss to NO, then the picker don't dismiss itself.
// If isOriginalPhoto is YES, user picked the original photo.
// You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
// The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
// 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosWithInfosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
,
NSArray
<
NSDictionary
*>
*
infos
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosWithInfosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
,
NSArray
<
NSDictionary
*>
*
infos
);
@property
(
nonatomic
,
copy
)
void
(
^
imagePickerControllerDidCancelHandle
)(
void
);
@property
(
nonatomic
,
copy
)
void
(
^
imagePickerControllerDidCancelHandle
)(
void
);
// If user picking a video, this handle will be called.
// 如果用户选择了一个视频,下面的handle会被执行
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingVideoHandle
)(
UIImage
*
coverImage
,
PHAsset
*
asset
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingVideoHandle
)(
UIImage
*
coverImage
,
PHAsset
*
asset
);
// If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingGifImageHandle
)(
UIImage
*
animatedImage
,
id
sourceAssets
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingGifImageHandle
)(
UIImage
*
animatedImage
,
id
sourceAssets
);
@property
(
nonatomic
,
weak
)
id
<
TZImagePickerControllerDelegate
>
pickerDelegate
;
@property
(
nonatomic
,
weak
)
id
<
TZImagePickerControllerDelegate
>
pickerDelegate
;
...
@@ -244,30 +259,27 @@
...
@@ -244,30 +259,27 @@
@protocol
TZImagePickerControllerDelegate
<
NSObject
>
@protocol
TZImagePickerControllerDelegate
<
NSObject
>
@optional
@optional
// The picker should dismiss itself; when it dismissed these
callback
will be called.
// The picker should dismiss itself; when it dismissed these
handle
will be called.
// You can also set autoDismiss to NO, then the picker don't dismiss itself.
// You can also set autoDismiss to NO, then the picker don't dismiss itself.
// If isOriginalPhoto is YES, user picked the original photo.
// If isOriginalPhoto is YES, user picked the original photo.
// You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
// You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
// The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
// The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的
代理方法
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的
handle
// 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
// 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
// photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
-
(
void
)
imagePickerController
:
(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:
(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:
(
NSArray
*
)
assets
isSelectOriginalPhoto
:
(
BOOL
)
isSelectOriginalPhoto
;
-
(
void
)
imagePickerController
:
(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:
(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:
(
NSArray
*
)
assets
isSelectOriginalPhoto
:
(
BOOL
)
isSelectOriginalPhoto
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
infos
:(
NSArray
<
NSDictionary
*>
*
)
infos
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
infos
:(
NSArray
<
NSDictionary
*>
*
)
infos
;
//- (void)imagePickerControllerDidCancel:(TZImagePickerController *)picker __attribute__((deprecated("Use -tz_imagePickerControllerDidCancel:.")));
-
(
void
)
tz_imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
-
(
void
)
tz_imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
// If user picking a video and allowPickingMultipleVideo is NO, this callback will be called.
// If user picking a video, this callback will be called.
// If allowPickingMultipleVideo is YES, will call imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// 如果用户选择了一个视频,下面的handle会被执行
// 如果用户选择了一个视频且allowPickingMultipleVideo是NO,下面的代理方法会被执行
// 如果allowPickingMultipleVideo是YES,将会调用imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingVideo
:(
UIImage
*
)
coverImage
sourceAssets
:(
PHAsset
*
)
asset
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingVideo
:(
UIImage
*
)
coverImage
sourceAssets
:(
PHAsset
*
)
asset
;
// If user picking a gif image and allowPickingMultipleVideo is NO, this callback will be called.
// If user picking a gif image, this callback will be called.
// If allowPickingMultipleVideo is YES, will call imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// 如果用户选择了一个gif图片,下面的handle会被执行
// 如果用户选择了一个gif图片且allowPickingMultipleVideo是NO,下面的代理方法会被执行
// 如果allowPickingMultipleVideo是YES,将会调用imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingGifImage
:(
UIImage
*
)
animatedImage
sourceAssets
:(
PHAsset
*
)
asset
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingGifImage
:(
UIImage
*
)
animatedImage
sourceAssets
:(
PHAsset
*
)
asset
;
// Decide album show or not't
// Decide album show or not't
...
@@ -288,7 +300,7 @@
...
@@ -288,7 +300,7 @@
@interface
UIImage
(
MyBundle
)
@interface
UIImage
(
MyBundle
)
+
(
UIImage
*
)
tz_
imageNamedFromMyBundle
:(
NSString
*
)
name
;
+
(
UIImage
*
)
imageNamedFromMyBundle
:(
NSString
*
)
name
;
@end
@end
...
@@ -297,7 +309,7 @@
...
@@ -297,7 +309,7 @@
+
(
CGFloat
)
tz_statusBarHeight
;
+
(
CGFloat
)
tz_statusBarHeight
;
// 获得Info.plist数据字典
// 获得Info.plist数据字典
+
(
NSDictionary
*
)
tz_getInfoDictionary
;
+
(
NSDictionary
*
)
tz_getInfoDictionary
;
+
(
BOOL
)
tz_
isRightToLeftLayout
;
+
(
BOOL
)
isRightToLeftLayout
;
@end
@end
...
...
ios/TZImagePickerController/TZImagePickerController.m
View file @
81edf1ae
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
//
//
// Created by 谭真 on 15/12/24.
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// Copyright © 2015年 谭真. All rights reserved.
// version 3.
1.9 - 2019.01.14
// version 3.
0.9 - 2018.10.09
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
#import "TZImagePickerController.h"
#import "TZImagePickerController.h"
...
@@ -235,7 +235,6 @@
...
@@ -235,7 +235,6 @@
self
=
[
super
initWithRootViewController
:
previewVc
];
self
=
[
super
initWithRootViewController
:
previewVc
];
if
(
self
)
{
if
(
self
)
{
self
.
maxImagesCount
=
1
;
self
.
maxImagesCount
=
1
;
self
.
allowPickingImage
=
YES
;
self
.
allowCrop
=
YES
;
self
.
allowCrop
=
YES
;
self
.
selectedAssets
=
[
NSMutableArray
arrayWithArray
:@[
asset
]];
self
.
selectedAssets
=
[
NSMutableArray
arrayWithArray
:@[
asset
]];
[
self
configDefaultSetting
];
[
self
configDefaultSetting
];
...
@@ -291,37 +290,37 @@
...
@@ -291,37 +290,37 @@
-
(
void
)
setTakePictureImageName
:
(
NSString
*
)
takePictureImageName
{
-
(
void
)
setTakePictureImageName
:
(
NSString
*
)
takePictureImageName
{
_takePictureImageName
=
takePictureImageName
;
_takePictureImageName
=
takePictureImageName
;
_takePictureImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
takePictureImageName
];
_takePictureImage
=
[
UIImage
imageNamedFromMyBundle
:
takePictureImageName
];
}
}
-
(
void
)
setPhotoSelImageName
:
(
NSString
*
)
photoSelImageName
{
-
(
void
)
setPhotoSelImageName
:
(
NSString
*
)
photoSelImageName
{
_photoSelImageName
=
photoSelImageName
;
_photoSelImageName
=
photoSelImageName
;
_photoSelImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoSelImageName
];
_photoSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoSelImageName
];
}
}
-
(
void
)
setPhotoDefImageName
:
(
NSString
*
)
photoDefImageName
{
-
(
void
)
setPhotoDefImageName
:
(
NSString
*
)
photoDefImageName
{
_photoDefImageName
=
photoDefImageName
;
_photoDefImageName
=
photoDefImageName
;
_photoDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoDefImageName
];
_photoDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoDefImageName
];
}
}
-
(
void
)
setPhotoNumberIconImageName
:
(
NSString
*
)
photoNumberIconImageName
{
-
(
void
)
setPhotoNumberIconImageName
:
(
NSString
*
)
photoNumberIconImageName
{
_photoNumberIconImageName
=
photoNumberIconImageName
;
_photoNumberIconImageName
=
photoNumberIconImageName
;
_photoNumberIconImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoNumberIconImageName
];
_photoNumberIconImage
=
[
UIImage
imageNamedFromMyBundle
:
photoNumberIconImageName
];
}
}
-
(
void
)
setPhotoPreviewOriginDefImageName
:
(
NSString
*
)
photoPreviewOriginDefImageName
{
-
(
void
)
setPhotoPreviewOriginDefImageName
:
(
NSString
*
)
photoPreviewOriginDefImageName
{
_photoPreviewOriginDefImageName
=
photoPreviewOriginDefImageName
;
_photoPreviewOriginDefImageName
=
photoPreviewOriginDefImageName
;
_photoPreviewOriginDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoPreviewOriginDefImageName
];
_photoPreviewOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoPreviewOriginDefImageName
];
}
}
-
(
void
)
setPhotoOriginDefImageName
:
(
NSString
*
)
photoOriginDefImageName
{
-
(
void
)
setPhotoOriginDefImageName
:
(
NSString
*
)
photoOriginDefImageName
{
_photoOriginDefImageName
=
photoOriginDefImageName
;
_photoOriginDefImageName
=
photoOriginDefImageName
;
_photoOriginDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoOriginDefImageName
];
_photoOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginDefImageName
];
}
}
-
(
void
)
setPhotoOriginSelImageName
:
(
NSString
*
)
photoOriginSelImageName
{
-
(
void
)
setPhotoOriginSelImageName
:
(
NSString
*
)
photoOriginSelImageName
{
_photoOriginSelImageName
=
photoOriginSelImageName
;
_photoOriginSelImageName
=
photoOriginSelImageName
;
_photoOriginSelImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoOriginSelImageName
];
_photoOriginSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginSelImageName
];
}
}
-
(
void
)
setIconThemeColor
:
(
UIColor
*
)
iconThemeColor
{
-
(
void
)
setIconThemeColor
:
(
UIColor
*
)
iconThemeColor
{
...
@@ -822,7 +821,7 @@
...
@@ -822,7 +821,7 @@
@implementation
UIImage
(
MyBundle
)
@implementation
UIImage
(
MyBundle
)
+
(
UIImage
*
)
tz_
imageNamedFromMyBundle
:(
NSString
*
)
name
{
+
(
UIImage
*
)
imageNamedFromMyBundle
:(
NSString
*
)
name
{
NSBundle
*
imageBundle
=
[
NSBundle
tz_imagePickerBundle
];
NSBundle
*
imageBundle
=
[
NSBundle
tz_imagePickerBundle
];
name
=
[
name
stringByAppendingString
:
@"@2x"
];
name
=
[
name
stringByAppendingString
:
@"@2x"
];
NSString
*
imagePath
=
[
imageBundle
pathForResource
:
name
ofType
:
@"png"
];
NSString
*
imagePath
=
[
imageBundle
pathForResource
:
name
ofType
:
@"png"
];
...
@@ -864,7 +863,7 @@
...
@@ -864,7 +863,7 @@
return
infoDict
?
infoDict
:
@{};
return
infoDict
?
infoDict
:
@{};
}
}
+
(
BOOL
)
tz_
isRightToLeftLayout
{
+
(
BOOL
)
isRightToLeftLayout
{
if
(
@available
(
iOS
9
.
0
,
*
))
{
if
(
@available
(
iOS
9
.
0
,
*
))
{
if
([
UIView
userInterfaceLayoutDirectionForSemanticContentAttribute
:
UISemanticContentAttributeUnspecified
]
==
UIUserInterfaceLayoutDirectionRightToLeft
)
{
if
([
UIView
userInterfaceLayoutDirectionForSemanticContentAttribute
:
UISemanticContentAttributeUnspecified
]
==
UIUserInterfaceLayoutDirectionRightToLeft
)
{
return
YES
;
return
YES
;
...
...
ios/TZImagePickerController/TZImageRequestOperation.h
deleted
100755 → 0
View file @
4624da7e
//
// TZImageRequestOperation.h
// TZImagePickerControllerFramework
//
// Created by 谭真 on 2018/12/20.
// Copyright © 2018 谭真. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Photos/Photos.h>
NS_ASSUME_NONNULL_BEGIN
@interface
TZImageRequestOperation
:
NSOperation
typedef
void
(
^
TZImageRequestCompletedBlock
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
);
typedef
void
(
^
TZImageRequestProgressBlock
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
);
@property
(
nonatomic
,
copy
,
nullable
)
TZImageRequestCompletedBlock
completedBlock
;
@property
(
nonatomic
,
copy
,
nullable
)
TZImageRequestProgressBlock
progressBlock
;
@property
(
nonatomic
,
strong
,
nullable
)
PHAsset
*
asset
;
@property
(
assign
,
nonatomic
,
getter
=
isExecuting
)
BOOL
executing
;
@property
(
assign
,
nonatomic
,
getter
=
isFinished
)
BOOL
finished
;
-
(
instancetype
)
initWithAsset
:(
PHAsset
*
)
asset
completion
:(
TZImageRequestCompletedBlock
)
completionBlock
progressHandler
:(
TZImageRequestProgressBlock
)
progressHandler
;
-
(
void
)
done
;
@end
NS_ASSUME_NONNULL_END
ios/TZImagePickerController/TZImageRequestOperation.m
deleted
100755 → 0
View file @
4624da7e
//
// TZImageRequestOperation.m
// TZImagePickerControllerFramework
//
// Created by 谭真 on 2018/12/20.
// Copyright © 2018 谭真. All rights reserved.
//
#import "TZImageRequestOperation.h"
#import "TZImageManager.h"
@implementation
TZImageRequestOperation
@synthesize
executing
=
_executing
;
@synthesize
finished
=
_finished
;
-
(
instancetype
)
initWithAsset
:(
PHAsset
*
)
asset
completion
:(
TZImageRequestCompletedBlock
)
completionBlock
progressHandler
:(
TZImageRequestProgressBlock
)
progressHandler
{
self
=
[
super
init
];
self
.
asset
=
asset
;
self
.
completedBlock
=
completionBlock
;
self
.
progressBlock
=
progressHandler
;
_executing
=
NO
;
_finished
=
NO
;
return
self
;
}
-
(
void
)
start
{
self
.
executing
=
YES
;
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
self
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
!
isDegraded
)
{
if
(
self
.
completedBlock
)
{
self
.
completedBlock
(
photo
,
info
,
isDegraded
);
}
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
1
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
[
self
done
];
});
}
});
}
progressHandler
:^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
self
.
progressBlock
)
{
self
.
progressBlock
(
progress
,
error
,
stop
,
info
);
}
});
}
networkAccessAllowed
:
YES
];
});
}
-
(
void
)
done
{
self
.
finished
=
YES
;
self
.
executing
=
NO
;
[
self
reset
];
}
-
(
void
)
reset
{
self
.
asset
=
nil
;
self
.
completedBlock
=
nil
;
self
.
progressBlock
=
nil
;
}
-
(
void
)
setFinished
:
(
BOOL
)
finished
{
[
self
willChangeValueForKey
:
@"isFinished"
];
_finished
=
finished
;
[
self
didChangeValueForKey
:
@"isFinished"
];
}
-
(
void
)
setExecuting
:
(
BOOL
)
executing
{
[
self
willChangeValueForKey
:
@"isExecuting"
];
_executing
=
executing
;
[
self
didChangeValueForKey
:
@"isExecuting"
];
}
-
(
BOOL
)
isAsynchronous
{
return
YES
;
}
@end
ios/TZImagePickerController/TZLocationManager.h
View file @
81edf1ae
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
@interface
TZLocationManager
:
NSObject
@interface
TZLocationManager
:
NSObject
+
(
instancetype
)
manager
NS_SWIFT_NAME
(
default
())
;
+
(
instancetype
)
manager
;
/// 开始定位
/// 开始定位
-
(
void
)
startLocation
;
-
(
void
)
startLocation
;
...
...
ios/TZImagePickerController/TZPhotoPickerController.m
View file @
81edf1ae
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
#import "TZGifPhotoPreviewController.h"
#import "TZGifPhotoPreviewController.h"
#import "TZLocationManager.h"
#import "TZLocationManager.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "TZImageRequestOperation.h"
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
,
UIAlertViewDelegate
>
{
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
,
UIAlertViewDelegate
>
{
NSMutableArray
*
_models
;
NSMutableArray
*
_models
;
...
@@ -39,11 +38,10 @@
...
@@ -39,11 +38,10 @@
@property
CGRect
previousPreheatRect
;
@property
CGRect
previousPreheatRect
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
@property
(
nonatomic
,
strong
)
TZCollectionView
*
collectionView
;
@property
(
nonatomic
,
strong
)
TZCollectionView
*
collectionView
;
@property
(
nonatomic
,
strong
)
UILabel
*
noDataLabel
;
@property
(
strong
,
nonatomic
)
UICollectionViewFlowLayout
*
layout
;
@property
(
strong
,
nonatomic
)
UICollectionViewFlowLayout
*
layout
;
@property
(
nonatomic
,
strong
)
UIImagePickerController
*
imagePickerVc
;
@property
(
nonatomic
,
strong
)
UIImagePickerController
*
imagePickerVc
;
@property
(
strong
,
nonatomic
)
CLLocation
*
location
;
@property
(
strong
,
nonatomic
)
CLLocation
*
location
;
@property
(
nonatomic
,
strong
)
NSOperationQueue
*
operationQueu
e
;
@property
(
assign
,
nonatomic
)
BOOL
useCachedImag
e
;
@end
@end
static
CGSize
AssetGridThumbnailSize
;
static
CGSize
AssetGridThumbnailSize
;
...
@@ -95,9 +93,6 @@ static CGFloat itemMargin = 5;
...
@@ -95,9 +93,6 @@ static CGFloat itemMargin = 5;
_showTakePhotoBtn
=
_model
.
isCameraRoll
&&
((
tzImagePickerVc
.
allowTakePicture
&&
tzImagePickerVc
.
allowPickingImage
)
||
(
tzImagePickerVc
.
allowTakeVideo
&&
tzImagePickerVc
.
allowPickingVideo
));
_showTakePhotoBtn
=
_model
.
isCameraRoll
&&
((
tzImagePickerVc
.
allowTakePicture
&&
tzImagePickerVc
.
allowPickingImage
)
||
(
tzImagePickerVc
.
allowTakeVideo
&&
tzImagePickerVc
.
allowPickingVideo
));
// [self resetCachedAssets];
// [self resetCachedAssets];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
didChangeStatusBarOrientationNotification
:
)
name
:
UIApplicationDidChangeStatusBarOrientationNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
didChangeStatusBarOrientationNotification
:
)
name
:
UIApplicationDidChangeStatusBarOrientationNotification
object
:
nil
];
self
.
operationQueue
=
[[
NSOperationQueue
alloc
]
init
];
self
.
operationQueue
.
maxConcurrentOperationCount
=
3
;
}
}
-
(
void
)
fetchAssetModels
{
-
(
void
)
fetchAssetModels
{
...
@@ -171,15 +166,6 @@ static CGFloat itemMargin = 5;
...
@@ -171,15 +166,6 @@ static CGFloat itemMargin = 5;
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
self
.
columnNumber
)
/
self
.
columnNumber
)
*
self
.
view
.
tz_width
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
self
.
columnNumber
)
/
self
.
columnNumber
)
*
self
.
view
.
tz_width
);
}
else
{
}
else
{
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
self
.
columnNumber
-
1
)
/
self
.
columnNumber
)
*
self
.
view
.
tz_width
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
self
.
columnNumber
-
1
)
/
self
.
columnNumber
)
*
self
.
view
.
tz_width
);
if
(
_models
.
count
==
0
)
{
_noDataLabel
=
[
UILabel
new
];
_noDataLabel
.
textAlignment
=
NSTextAlignmentCenter
;
_noDataLabel
.
text
=
[
NSBundle
tz_localizedStringForKey
:
@"No Photos or Videos"
];
CGFloat
rgb
=
153
/
256
.
0
;
_noDataLabel
.
textColor
=
[
UIColor
colorWithRed
:
rgb
green
:
rgb
blue
:
rgb
alpha
:
1
.
0
];
_noDataLabel
.
font
=
[
UIFont
boldSystemFontOfSize
:
20
];
[
_collectionView
addSubview
:
_noDataLabel
];
}
}
}
[
self
.
view
addSubview
:
_collectionView
];
[
self
.
view
addSubview
:
_collectionView
];
[
_collectionView
registerClass
:[
TZAssetCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCell"
];
[
_collectionView
registerClass
:[
TZAssetCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCell"
];
...
@@ -225,7 +211,7 @@ static CGFloat itemMargin = 5;
...
@@ -225,7 +211,7 @@ static CGFloat itemMargin = 5;
if
(
tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
if
(
tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
[
TZCommonTools
tz_
isRightToLeftLayout
]
?
10
:
-
10
,
0
,
0
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
[
TZCommonTools
isRightToLeftLayout
]
?
10
:
-
10
,
0
,
0
);
[
_originalPhotoButton
addTarget
:
self
action
:
@selector
(
originalPhotoButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_originalPhotoButton
addTarget
:
self
action
:
@selector
(
originalPhotoButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
_originalPhotoButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_originalPhotoButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
[
_originalPhotoButton
setTitle
:
tzImagePickerVc
.
fullImageBtnTitleStr
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setTitle
:
tzImagePickerVc
.
fullImageBtnTitleStr
forState
:
UIControlStateNormal
];
...
@@ -307,7 +293,6 @@ static CGFloat itemMargin = 5;
...
@@ -307,7 +293,6 @@ static CGFloat itemMargin = 5;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
toolBarHeight
:
self
.
view
.
tz_height
;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
toolBarHeight
:
self
.
view
.
tz_height
;
}
}
_collectionView
.
frame
=
CGRectMake
(
0
,
top
,
self
.
view
.
tz_width
,
collectionViewHeight
);
_collectionView
.
frame
=
CGRectMake
(
0
,
top
,
self
.
view
.
tz_width
,
collectionViewHeight
);
_noDataLabel
.
frame
=
_collectionView
.
bounds
;
CGFloat
itemWH
=
(
self
.
view
.
tz_width
-
(
self
.
columnNumber
+
1
)
*
itemMargin
)
/
self
.
columnNumber
;
CGFloat
itemWH
=
(
self
.
view
.
tz_width
-
(
self
.
columnNumber
+
1
)
*
itemMargin
)
/
self
.
columnNumber
;
_layout
.
itemSize
=
CGSizeMake
(
itemWH
,
itemWH
);
_layout
.
itemSize
=
CGSizeMake
(
itemWH
,
itemWH
);
_layout
.
minimumInteritemSpacing
=
itemMargin
;
_layout
.
minimumInteritemSpacing
=
itemMargin
;
...
@@ -345,7 +330,6 @@ static CGFloat itemMargin = 5;
...
@@ -345,7 +330,6 @@ static CGFloat itemMargin = 5;
_divideLine
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
1
);
_divideLine
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
1
);
[
TZImageManager
manager
].
columnNumber
=
[
TZImageManager
manager
].
columnNumber
;
[
TZImageManager
manager
].
columnNumber
=
[
TZImageManager
manager
].
columnNumber
;
[
TZImageManager
manager
].
photoWidth
=
tzImagePickerVc
.
photoWidth
;
[
self
.
collectionView
reloadData
];
[
self
.
collectionView
reloadData
];
if
(
tzImagePickerVc
.
photoPickerPageDidLayoutSubviewsBlock
)
{
if
(
tzImagePickerVc
.
photoPickerPageDidLayoutSubviewsBlock
)
{
...
@@ -405,7 +389,7 @@ static CGFloat itemMargin = 5;
...
@@ -405,7 +389,7 @@ static CGFloat itemMargin = 5;
__block
UIAlertController
*
alertView
;
__block
UIAlertController
*
alertView
;
for
(
NSInteger
i
=
0
;
i
<
tzImagePickerVc
.
selectedModels
.
count
;
i
++
)
{
for
(
NSInteger
i
=
0
;
i
<
tzImagePickerVc
.
selectedModels
.
count
;
i
++
)
{
TZAssetModel
*
model
=
tzImagePickerVc
.
selectedModels
[
i
];
TZAssetModel
*
model
=
tzImagePickerVc
.
selectedModels
[
i
];
TZImageRequestOperation
*
operation
=
[[
TZImageRequestOperation
alloc
]
initWithAsset
:
model
.
asset
completion
:
^
(
UIImage
*
_Nonnull
photo
,
NSDictionary
*
_Nonnull
info
,
BOOL
isDegraded
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
isDegraded
)
return
;
if
(
isDegraded
)
return
;
if
(
photo
)
{
if
(
photo
)
{
if
(
!
[
TZImagePickerConfig
sharedInstance
].
notScaleImage
)
{
if
(
!
[
TZImagePickerConfig
sharedInstance
].
notScaleImage
)
{
...
@@ -422,7 +406,7 @@ static CGFloat itemMargin = 5;
...
@@ -422,7 +406,7 @@ static CGFloat itemMargin = 5;
[
tzImagePickerVc
hideAlertView
:
alertView
];
[
tzImagePickerVc
hideAlertView
:
alertView
];
[
self
didGetAllPhotos
:
photos
assets
:
assets
infoArr
:
infoArr
];
[
self
didGetAllPhotos
:
photos
assets
:
assets
infoArr
:
infoArr
];
}
}
}
progressHandler
:^
(
double
progress
,
NSError
*
_Nonnull
error
,
BOOL
*
_Nonnull
stop
,
NSDictionary
*
_Nonnull
info
)
{
}
progressHandler
:^
(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
)
{
// 如果图片正在从iCloud同步中,提醒用户
// 如果图片正在从iCloud同步中,提醒用户
if
(
progress
<
1
&&
havenotShowAlert
&&
!
alertView
)
{
if
(
progress
<
1
&&
havenotShowAlert
&&
!
alertView
)
{
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
...
@@ -433,8 +417,7 @@ static CGFloat itemMargin = 5;
...
@@ -433,8 +417,7 @@ static CGFloat itemMargin = 5;
if
(
progress
>=
1
)
{
if
(
progress
>=
1
)
{
havenotShowAlert
=
YES
;
havenotShowAlert
=
YES
;
}
}
}];
}
networkAccessAllowed
:
YES
];
[
self
.
operationQueue
addOperation
:
operation
];
}
}
}
}
if
(
tzImagePickerVc
.
selectedModels
.
count
<=
0
||
tzImagePickerVc
.
onlyReturnAsset
)
{
if
(
tzImagePickerVc
.
selectedModels
.
count
<=
0
||
tzImagePickerVc
.
onlyReturnAsset
)
{
...
@@ -512,6 +495,7 @@ static CGFloat itemMargin = 5;
...
@@ -512,6 +495,7 @@ static CGFloat itemMargin = 5;
cell
.
allowPickingMultipleVideo
=
tzImagePickerVc
.
allowPickingMultipleVideo
;
cell
.
allowPickingMultipleVideo
=
tzImagePickerVc
.
allowPickingMultipleVideo
;
cell
.
photoDefImage
=
tzImagePickerVc
.
photoDefImage
;
cell
.
photoDefImage
=
tzImagePickerVc
.
photoDefImage
;
cell
.
photoSelImage
=
tzImagePickerVc
.
photoSelImage
;
cell
.
photoSelImage
=
tzImagePickerVc
.
photoSelImage
;
cell
.
useCachedImage
=
self
.
useCachedImage
;
cell
.
assetCellDidSetModelBlock
=
tzImagePickerVc
.
assetCellDidSetModelBlock
;
cell
.
assetCellDidSetModelBlock
=
tzImagePickerVc
.
assetCellDidSetModelBlock
;
cell
.
assetCellDidLayoutSubviewsBlock
=
tzImagePickerVc
.
assetCellDidLayoutSubviewsBlock
;
cell
.
assetCellDidLayoutSubviewsBlock
=
tzImagePickerVc
.
assetCellDidLayoutSubviewsBlock
;
TZAssetModel
*
model
;
TZAssetModel
*
model
;
...
@@ -556,7 +540,7 @@ static CGFloat itemMargin = 5;
...
@@ -556,7 +540,7 @@ static CGFloat itemMargin = 5;
}
}
[
strongSelf
refreshBottomToolBarStatus
];
[
strongSelf
refreshBottomToolBarStatus
];
if
(
tzImagePickerVc
.
showSelectedIndex
||
tzImagePickerVc
.
showPhotoCannotSelectLayer
)
{
if
(
tzImagePickerVc
.
showSelectedIndex
||
tzImagePickerVc
.
showPhotoCannotSelectLayer
)
{
[
[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION"
object
:
strongSelf
.
navigationController
];
[
strongSelf
setUseCachedImageAndReloadData
];
}
}
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
}
else
{
}
else
{
...
@@ -570,10 +554,11 @@ static CGFloat itemMargin = 5;
...
@@ -570,10 +554,11 @@ static CGFloat itemMargin = 5;
}
}
strongCell
.
selectPhotoButton
.
selected
=
YES
;
strongCell
.
selectPhotoButton
.
selected
=
YES
;
model
.
isSelected
=
YES
;
model
.
isSelected
=
YES
;
[
tzImagePickerVc
addSelectedModel
:
model
];
if
(
tzImagePickerVc
.
showSelectedIndex
||
tzImagePickerVc
.
showPhotoCannotSelectLayer
)
{
if
(
tzImagePickerVc
.
showSelectedIndex
||
tzImagePickerVc
.
showPhotoCannotSelectLayer
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION"
object
:
strongSelf
.
navigationController
];
model
.
needOscillatoryAnimation
=
YES
;
[
strongSelf
setUseCachedImageAndReloadData
];
}
}
[
tzImagePickerVc
addSelectedModel
:
model
];
[
strongSelf
refreshBottomToolBarStatus
];
[
strongSelf
refreshBottomToolBarStatus
];
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
}
else
{
}
else
{
...
@@ -631,6 +616,14 @@ static CGFloat itemMargin = 5;
...
@@ -631,6 +616,14 @@ static CGFloat itemMargin = 5;
#pragma mark - Private Method
#pragma mark - Private Method
-
(
void
)
setUseCachedImageAndReloadData
{
self
.
useCachedImage
=
YES
;
[
self
.
collectionView
reloadData
];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
1
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
self
.
useCachedImage
=
NO
;
});
}
/// 拍照按钮点击事件
/// 拍照按钮点击事件
-
(
void
)
takePhoto
{
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.h
View file @
81edf1ae
...
@@ -58,7 +58,6 @@
...
@@ -58,7 +58,6 @@
@property
(
strong
,
nonatomic
)
AVPlayerLayer
*
playerLayer
;
@property
(
strong
,
nonatomic
)
AVPlayerLayer
*
playerLayer
;
@property
(
strong
,
nonatomic
)
UIButton
*
playButton
;
@property
(
strong
,
nonatomic
)
UIButton
*
playButton
;
@property
(
strong
,
nonatomic
)
UIImage
*
cover
;
@property
(
strong
,
nonatomic
)
UIImage
*
cover
;
@property
(
nonatomic
,
strong
)
NSURL
*
videoURL
;
-
(
void
)
pausePlayerAndShowNaviBar
;
-
(
void
)
pausePlayerAndShowNaviBar
;
@end
@end
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.m
View file @
81edf1ae
...
@@ -224,8 +224,6 @@
...
@@ -224,8 +224,6 @@
self
.
imageRequestID
=
0
;
self
.
imageRequestID
=
0
;
}
}
}
networkAccessAllowed
:
YES
];
}
networkAccessAllowed
:
YES
];
[
self
configMaximumZoomScale
];
}
}
-
(
void
)
recoverSubviews
{
-
(
void
)
recoverSubviews
{
...
@@ -259,8 +257,9 @@
...
@@ -259,8 +257,9 @@
[
self
refreshScrollViewContentSize
];
[
self
refreshScrollViewContentSize
];
}
}
-
(
void
)
configMaximumZoomScale
{
-
(
void
)
setAllowCrop
:
(
BOOL
)
allowCrop
{
_scrollView
.
maximumZoomScale
=
_allowCrop
?
4
.
0
:
2
.
5
;
_allowCrop
=
allowCrop
;
_scrollView
.
maximumZoomScale
=
allowCrop
?
4
.
0
:
2
.
5
;
if
([
self
.
asset
isKindOfClass
:[
PHAsset
class
]])
{
if
([
self
.
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHAsset
*
phAsset
=
(
PHAsset
*
)
self
.
asset
;
PHAsset
*
phAsset
=
(
PHAsset
*
)
self
.
asset
;
...
@@ -355,7 +354,7 @@
...
@@ -355,7 +354,7 @@
@implementation
TZVideoPreviewCell
@implementation
TZVideoPreviewCell
-
(
void
)
configSubviews
{
-
(
void
)
configSubviews
{
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
appWillResignActiveNotification
)
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
pausePlayerAndShowNaviBar
)
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
}
}
-
(
void
)
configPlayButton
{
-
(
void
)
configPlayButton
{
...
@@ -363,8 +362,8 @@
...
@@ -363,8 +362,8 @@
[
_playButton
removeFromSuperview
];
[
_playButton
removeFromSuperview
];
}
}
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
addSubview
:
_playButton
];
[
self
addSubview
:
_playButton
];
}
}
...
@@ -374,11 +373,6 @@
...
@@ -374,11 +373,6 @@
[
self
configMoviePlayer
];
[
self
configMoviePlayer
];
}
}
-
(
void
)
setVideoURL
:
(
NSURL
*
)
videoURL
{
_videoURL
=
videoURL
;
[
self
configMoviePlayer
];
}
-
(
void
)
configMoviePlayer
{
-
(
void
)
configMoviePlayer
{
if
(
_player
)
{
if
(
_player
)
{
[
_playerLayer
removeFromSuperlayer
];
[
_playerLayer
removeFromSuperlayer
];
...
@@ -387,29 +381,20 @@
...
@@ -387,29 +381,20 @@
_player
=
nil
;
_player
=
nil
;
}
}
if
(
self
.
model
&&
self
.
model
.
asset
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
self
.
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
self
.
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
self
->
_cover
=
photo
;
self
.
cover
=
photo
;
}];
}];
[[
TZImageManager
manager
]
getVideoWithAsset
:
self
.
model
.
asset
completion
:
^
(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
)
{
[[
TZImageManager
manager
]
getVideoWithAsset
:
self
.
model
.
asset
completion
:
^
(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
self
->
_player
=
[
AVPlayer
playerWithPlayerItem
:
playerItem
];
[
self
configPlayerWithItem
:
playerItem
];
self
->
_playerLayer
=
[
AVPlayerLayer
playerLayerWithPlayer
:
self
->
_player
];
});
self
->
_playerLayer
.
backgroundColor
=
[
UIColor
blackColor
].
CGColor
;
}];
self
->
_playerLayer
.
frame
=
self
.
bounds
;
}
else
{
[
self
.
layer
addSublayer
:
self
->
_playerLayer
];
AVPlayerItem
*
playerItem
=
[
AVPlayerItem
playerItemWithURL
:
self
.
videoURL
];
[
self
configPlayButton
];
[
self
configPlayerWithItem
:
playerItem
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
pausePlayerAndShowNaviBar
)
name
:
AVPlayerItemDidPlayToEndTimeNotification
object
:
self
->
_player
.
currentItem
];
}
});
}
}];
-
(
void
)
configPlayerWithItem
:
(
AVPlayerItem
*
)
playerItem
{
self
.
player
=
[
AVPlayer
playerWithPlayerItem
:
playerItem
];
self
.
playerLayer
=
[
AVPlayerLayer
playerLayerWithPlayer
:
self
.
player
];
self
.
playerLayer
.
backgroundColor
=
[
UIColor
blackColor
].
CGColor
;
self
.
playerLayer
.
frame
=
self
.
bounds
;
[
self
.
layer
addSublayer
:
self
.
playerLayer
];
[
self
configPlayButton
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
pausePlayerAndShowNaviBar
)
name
:
AVPlayerItemDidPlayToEndTimeNotification
object
:
self
.
player
.
currentItem
];
}
}
-
(
void
)
layoutSubviews
{
-
(
void
)
layoutSubviews
{
...
@@ -419,17 +404,7 @@
...
@@ -419,17 +404,7 @@
}
}
-
(
void
)
photoPreviewCollectionViewDidScroll
{
-
(
void
)
photoPreviewCollectionViewDidScroll
{
if
(
_player
&&
_player
.
rate
!=
0
.
0
)
{
[
self
pausePlayerAndShowNaviBar
];
[
self
pausePlayerAndShowNaviBar
];
}
}
#pragma mark - Notification
-
(
void
)
appWillResignActiveNotification
{
if
(
_player
&&
_player
.
rate
!=
0
.
0
)
{
[
self
pausePlayerAndShowNaviBar
];
}
}
}
#pragma mark - Click Event
#pragma mark - Click Event
...
@@ -451,10 +426,12 @@
...
@@ -451,10 +426,12 @@
}
}
-
(
void
)
pausePlayerAndShowNaviBar
{
-
(
void
)
pausePlayerAndShowNaviBar
{
[
_player
pause
];
if
(
_player
.
rate
!=
0
.
0
)
{
[
_playButton
setImage
:[
UIImage
tz_imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_player
pause
];
if
(
self
.
singleTapGestureBlock
)
{
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
self
.
singleTapGestureBlock
();
if
(
self
.
singleTapGestureBlock
)
{
self
.
singleTapGestureBlock
();
}
}
}
}
}
...
...
ios/TZImagePickerController/TZPhotoPreviewController.m
View file @
81edf1ae
...
@@ -105,7 +105,7 @@
...
@@ -105,7 +105,7 @@
_naviBar
.
backgroundColor
=
[
UIColor
colorWithRed
:(
34
/
255
.
0
)
green
:(
34
/
255
.
0
)
blue
:
(
34
/
255
.
0
)
alpha
:
0
.
7
];
_naviBar
.
backgroundColor
=
[
UIColor
colorWithRed
:(
34
/
255
.
0
)
green
:(
34
/
255
.
0
)
blue
:
(
34
/
255
.
0
)
alpha
:
0
.
7
];
_backButton
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectZero
];
_backButton
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectZero
];
[
_backButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"navi_back"
]
forState
:
UIControlStateNormal
];
[
_backButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"navi_back"
]
forState
:
UIControlStateNormal
];
[
_backButton
setTitleColor
:[
UIColor
whiteColor
]
forState
:
UIControlStateNormal
];
[
_backButton
setTitleColor
:[
UIColor
whiteColor
]
forState
:
UIControlStateNormal
];
[
_backButton
addTarget
:
self
action
:
@selector
(
backButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_backButton
addTarget
:
self
action
:
@selector
(
backButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
...
@@ -137,7 +137,7 @@
...
@@ -137,7 +137,7 @@
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
[
TZCommonTools
tz_
isRightToLeftLayout
]
?
10
:
-
10
,
0
,
0
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
[
TZCommonTools
isRightToLeftLayout
]
?
10
:
-
10
,
0
,
0
);
_originalPhotoButton
.
backgroundColor
=
[
UIColor
clearColor
];
_originalPhotoButton
.
backgroundColor
=
[
UIColor
clearColor
];
[
_originalPhotoButton
addTarget
:
self
action
:
@selector
(
originalPhotoButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_originalPhotoButton
addTarget
:
self
action
:
@selector
(
originalPhotoButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
_originalPhotoButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
13
];
_originalPhotoButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
13
];
...
@@ -502,10 +502,7 @@
...
@@ -502,10 +502,7 @@
if
([
cell
isKindOfClass
:[
TZPhotoPreviewCell
class
]])
{
if
([
cell
isKindOfClass
:[
TZPhotoPreviewCell
class
]])
{
[(
TZPhotoPreviewCell
*
)
cell
recoverSubviews
];
[(
TZPhotoPreviewCell
*
)
cell
recoverSubviews
];
}
else
if
([
cell
isKindOfClass
:[
TZVideoPreviewCell
class
]])
{
}
else
if
([
cell
isKindOfClass
:[
TZVideoPreviewCell
class
]])
{
TZVideoPreviewCell
*
videoCell
=
(
TZVideoPreviewCell
*
)
cell
;
[(
TZVideoPreviewCell
*
)
cell
pausePlayerAndShowNaviBar
];
if
(
videoCell
.
player
&&
videoCell
.
player
.
rate
!=
0
.
0
)
{
[
videoCell
pausePlayerAndShowNaviBar
];
}
}
}
}
}
...
@@ -577,7 +574,7 @@
...
@@ -577,7 +574,7 @@
}
}
-
(
NSInteger
)
currentIndex
{
-
(
NSInteger
)
currentIndex
{
return
[
TZCommonTools
tz_
isRightToLeftLayout
]
?
self
.
models
.
count
-
_currentIndex
-
1
:
_currentIndex
;
return
[
TZCommonTools
isRightToLeftLayout
]
?
self
.
models
.
count
-
_currentIndex
-
1
:
_currentIndex
;
}
}
@end
@end
ios/TZImagePickerController/TZVideoPlayerController.m
View file @
81edf1ae
...
@@ -93,8 +93,8 @@
...
@@ -93,8 +93,8 @@
-
(
void
)
configPlayButton
{
-
(
void
)
configPlayButton
{
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
_playButton
];
[
self
.
view
addSubview
:
_playButton
];
}
}
...
@@ -204,7 +204,7 @@
...
@@ -204,7 +204,7 @@
[
_player
pause
];
[
_player
pause
];
_toolBar
.
hidden
=
NO
;
_toolBar
.
hidden
=
NO
;
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
self
.
needShowStatusBar
)
{
if
(
self
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
...
...
package.json
View file @
81edf1ae
{
{
"name"
:
"react-native-syan-image-picker"
,
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.3.
1
"
,
"version"
:
"0.3.
2
"
,
"description"
:
"React-Native 多图片选择 支持裁剪 压缩"
,
"description"
:
"React-Native 多图片选择 支持裁剪 压缩"
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
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