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
Expand all
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 {
allowPickingGif
:
true
,
allowPickingImage
:
false
,
allowPickingMultipleVideo
:
true
,
videoMaximumDuration
:
20
videoMaximumDuration
:
20
,
...
options
};
RNSyanImagePicker
.
openVideoPicker
(
optionObj
,
callback
)
}
...
...
ios/RNSyanImagePicker.m
View file @
81edf1ae
...
...
@@ -164,6 +164,14 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
{
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
];
if
(
selectArray
.
count
==
assets
.
count
)
{
callback
(@[[
NSNull
null
],
selectArray
]);
...
...
@@ -183,16 +191,24 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
[
weakPicker
showProgressHUD
];
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
presetName
:
AVAssetExportPreset640x480
success
:^
(
NSString
*
outputPath
)
{
NSLog
(
@"视频导出到本地完成,沙盒路径为:%@"
,
outputPath
);
NSMutableDictionary
*
phot
o
=
[
NSMutableDictionary
dictionary
];
phot
o
[
@"uri"
]
=
outputPath
;
phot
o
[
@"fileName"
]
=
[
asset
valueForKey
:
@"filename"
];
NSMutableDictionary
*
vide
o
=
[
NSMutableDictionary
dictionary
];
vide
o
[
@"uri"
]
=
outputPath
;
vide
o
[
@"fileName"
]
=
[
asset
valueForKey
:
@"filename"
];
PHAssetResource
*
resource
=
[[
PHAssetResource
assetResourcesForAsset
:
asset
]
firstObject
];
long
long
size
=
[[
resource
valueForKey
:
@"fileSize"
]
longLongValue
];
phot
o
[
@"size"
]
=
@
(
size
);
vide
o
[
@"size"
]
=
@
(
size
);
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
hideProgressHUD
];
}
failure
:^
(
NSString
*
errorMessage
,
NSError
*
error
)
{
...
...
ios/TZImagePickerController/TZAssetCell.h
View file @
81edf1ae
...
...
@@ -35,6 +35,7 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
assign
)
BOOL
showSelectBtn
;
@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
(
^
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 @@
@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
{
_model
=
model
;
self
.
representedAssetIdentifier
=
model
.
asset
.
localIdentifier
;
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
// 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
;
}
else
{
// NSLog(@"this cell is showing other asset");
if
(
self
.
useCachedImage
&&
model
.
cachedImage
)
{
self
.
imageView
.
image
=
model
.
cachedImage
;
}
else
{
self
.
model
.
cachedImage
=
nil
;
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
// 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
];
// NSLog(@"cancelImageRequest %d",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
];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
self
.
imageRequestID
=
imageRequestID
;
}
self
.
imageRequestID
=
imageRequestID
;
self
.
selectPhotoButton
.
selected
=
model
.
isSelected
;
self
.
selectImageView
.
image
=
self
.
selectPhotoButton
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
self
.
indexLabel
.
hidden
=
!
self
.
selectPhotoButton
.
isSelected
;
...
...
@@ -73,6 +73,10 @@
}
else
{
[
self
cancelBigImageRequest
];
}
if
(
model
.
needOscillatoryAnimation
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
self
.
selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
model
.
needOscillatoryAnimation
=
NO
;
[
self
setNeedsLayout
];
if
(
self
.
assetCellDidSetModelBlock
)
{
...
...
@@ -140,7 +144,9 @@
}
self
.
selectImageView
.
image
=
sender
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
if
(
sender
.
isSelected
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
if
(
!
[
TZImagePickerConfig
sharedInstance
].
showSelectedIndex
&&
!
[
TZImagePickerConfig
sharedInstance
].
showPhotoCannotSelectLayer
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
// 用户选中了该图片,提前获取一下大图
[
self
requestBigImage
];
}
else
{
// 取消选中,取消大图的获取
...
...
@@ -179,8 +185,7 @@
[
self
hideProgressView
];
}
}
else
{
// 快速连续点几次,会EXC_BAD_ACCESS...
// *stop = YES;
*
stop
=
YES
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
self
cancelBigImageRequest
];
}
...
...
@@ -194,22 +199,6 @@
[
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
-
(
UIButton
*
)
selectPhotoButton
{
...
...
@@ -270,7 +259,7 @@
-
(
UIImageView
*
)
videoImgView
{
if
(
_videoImgView
==
nil
)
{
UIImageView
*
videoImgView
=
[[
UIImageView
alloc
]
init
];
[
videoImgView
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"VideoSendIcon"
]];
[
videoImgView
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"VideoSendIcon"
]];
[
self
.
bottomView
addSubview
:
videoImgView
];
_videoImgView
=
videoImgView
;
}
...
...
@@ -349,10 +338,6 @@
}
}
-
(
void
)
dealloc
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
}
@end
@interface
TZAlbumCell
()
...
...
ios/TZImagePickerController/TZAssetModel.h
View file @
81edf1ae
...
...
@@ -23,7 +23,9 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
strong
)
PHAsset
*
asset
;
@property
(
nonatomic
,
assign
)
BOOL
isSelected
;
///< The select status of a photo, default is No
@property
(
nonatomic
,
assign
)
TZAssetModelMediaType
type
;
@property
(
assign
,
nonatomic
)
BOOL
needOscillatoryAnimation
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
strong
,
nonatomic
)
UIImage
*
cachedImage
;
/// Init a photo dataModel With a PHAsset
/// 用一个PHAsset实例,初始化一个照片模型
...
...
ios/TZImagePickerController/TZImageManager.h
View file @
81edf1ae
...
...
@@ -58,22 +58,21 @@
-
(
void
)
getAssetFromFetchResult
:(
PHFetchResult
*
)
result
atIndex
:(
NSInteger
)
index
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAssetModel
*
model
))
completion
;
/// 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
;
-
(
PHImageRequestID
)
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
;
-
(
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
;
-
(
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
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
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
;
-
(
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
;
-
(
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
;
-
(
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 获取原图
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
-
(
PHImageRequestID
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
PHImageRequestID
)
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
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
// 该方法中,completion只会走一次
-
(
PHImageRequestID
)
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
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 保存照片
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
...
...
ios/TZImagePickerController/TZImageManager.m
View file @
81edf1ae
This diff is collapsed.
Click to expand it.
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";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/vi.lproj/Localizable.strings
View file @
81edf1ae
...
...
@@ -9,7 +9,6 @@
"Preview" = "Xem trước";
"Full image" = "Hình gốc";
"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";
"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";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/zh-Hans.lproj/Localizable.strings
View file @
81edf1ae
B
"OK" = "确定";
...
...
ios/TZImagePickerController/TZImagePickerController.bundle/zh-Hant.lproj/Localizable.strings
View file @
81edf1ae
B
"OK" = "確定";
...
...
ios/TZImagePickerController/TZImagePickerController.h
View file @
81edf1ae
...
...
@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// 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
/*
...
...
@@ -127,8 +127,8 @@
/// Default is white color with 0.8 alpha;
@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
/// 默认是
YES,如果设置为NO,内部
会缩放图片到photoWidth像素宽
/// Default is
No, if set YES, the result photo will not
be scaled to photoWidth pixel width. The photoWidth default is 828px
/// 默认是
NO,如果设置为YES,内部不
会缩放图片到photoWidth像素宽
@property
(
assign
,
nonatomic
)
BOOL
notScaleImage
;
/// 默认是NO,如果设置为YES,导出视频时会修正转向(慎重设为YES,可能导致部分安卓下拍的视频导出失败)
...
...
@@ -230,11 +230,26 @@
#pragma mark -
-
(
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
(
^
didFinishPickingPhotosWithInfosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
,
NSArray
<
NSDictionary
*>
*
infos
);
@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
);
// If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingGifImageHandle
)(
UIImage
*
animatedImage
,
id
sourceAssets
);
@property
(
nonatomic
,
weak
)
id
<
TZImagePickerControllerDelegate
>
pickerDelegate
;
...
...
@@ -244,30 +259,27 @@
@protocol
TZImagePickerControllerDelegate
<
NSObject
>
@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.
// 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的时候,会执行下面的
代理方法
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的
handle
// 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// 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
infos
:(
NSArray
<
NSDictionary
*>
*
)
infos
;
//- (void)imagePickerControllerDidCancel:(TZImagePickerController *)picker __attribute__((deprecated("Use -tz_imagePickerControllerDidCancel:.")));
-
(
void
)
tz_imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
// If user picking a video and allowPickingMultipleVideo is NO, this callback will be called.
// If allowPickingMultipleVideo is YES, will call imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// 如果用户选择了一个视频且allowPickingMultipleVideo是NO,下面的代理方法会被执行
// 如果allowPickingMultipleVideo是YES,将会调用imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// If user picking a video, this callback will be called.
// 如果用户选择了一个视频,下面的handle会被执行
-
(
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 allowPickingMultipleVideo is YES, will call imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// 如果用户选择了一个gif图片且allowPickingMultipleVideo是NO,下面的代理方法会被执行
// 如果allowPickingMultipleVideo是YES,将会调用imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:
// If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingGifImage
:(
UIImage
*
)
animatedImage
sourceAssets
:(
PHAsset
*
)
asset
;
// Decide album show or not't
...
...
@@ -288,7 +300,7 @@
@interface
UIImage
(
MyBundle
)
+
(
UIImage
*
)
tz_
imageNamedFromMyBundle
:(
NSString
*
)
name
;
+
(
UIImage
*
)
imageNamedFromMyBundle
:(
NSString
*
)
name
;
@end
...
...
@@ -297,7 +309,7 @@
+
(
CGFloat
)
tz_statusBarHeight
;
// 获得Info.plist数据字典
+
(
NSDictionary
*
)
tz_getInfoDictionary
;
+
(
BOOL
)
tz_
isRightToLeftLayout
;
+
(
BOOL
)
isRightToLeftLayout
;
@end
...
...
ios/TZImagePickerController/TZImagePickerController.m
View file @
81edf1ae
...
...
@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// 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
#import "TZImagePickerController.h"
...
...
@@ -235,7 +235,6 @@
self
=
[
super
initWithRootViewController
:
previewVc
];
if
(
self
)
{
self
.
maxImagesCount
=
1
;
self
.
allowPickingImage
=
YES
;
self
.
allowCrop
=
YES
;
self
.
selectedAssets
=
[
NSMutableArray
arrayWithArray
:@[
asset
]];
[
self
configDefaultSetting
];
...
...
@@ -291,37 +290,37 @@
-
(
void
)
setTakePictureImageName
:
(
NSString
*
)
takePictureImageName
{
_takePictureImageName
=
takePictureImageName
;
_takePictureImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
takePictureImageName
];
_takePictureImage
=
[
UIImage
imageNamedFromMyBundle
:
takePictureImageName
];
}
-
(
void
)
setPhotoSelImageName
:
(
NSString
*
)
photoSelImageName
{
_photoSelImageName
=
photoSelImageName
;
_photoSelImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoSelImageName
];
_photoSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoSelImageName
];
}
-
(
void
)
setPhotoDefImageName
:
(
NSString
*
)
photoDefImageName
{
_photoDefImageName
=
photoDefImageName
;
_photoDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoDefImageName
];
_photoDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoDefImageName
];
}
-
(
void
)
setPhotoNumberIconImageName
:
(
NSString
*
)
photoNumberIconImageName
{
_photoNumberIconImageName
=
photoNumberIconImageName
;
_photoNumberIconImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoNumberIconImageName
];
_photoNumberIconImage
=
[
UIImage
imageNamedFromMyBundle
:
photoNumberIconImageName
];
}
-
(
void
)
setPhotoPreviewOriginDefImageName
:
(
NSString
*
)
photoPreviewOriginDefImageName
{
_photoPreviewOriginDefImageName
=
photoPreviewOriginDefImageName
;
_photoPreviewOriginDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoPreviewOriginDefImageName
];
_photoPreviewOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoPreviewOriginDefImageName
];
}
-
(
void
)
setPhotoOriginDefImageName
:
(
NSString
*
)
photoOriginDefImageName
{
_photoOriginDefImageName
=
photoOriginDefImageName
;
_photoOriginDefImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoOriginDefImageName
];
_photoOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginDefImageName
];
}
-
(
void
)
setPhotoOriginSelImageName
:
(
NSString
*
)
photoOriginSelImageName
{
_photoOriginSelImageName
=
photoOriginSelImageName
;
_photoOriginSelImage
=
[
UIImage
tz_
imageNamedFromMyBundle
:
photoOriginSelImageName
];
_photoOriginSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginSelImageName
];
}
-
(
void
)
setIconThemeColor
:
(
UIColor
*
)
iconThemeColor
{
...
...
@@ -822,7 +821,7 @@
@implementation
UIImage
(
MyBundle
)
+
(
UIImage
*
)
tz_
imageNamedFromMyBundle
:(
NSString
*
)
name
{
+
(
UIImage
*
)
imageNamedFromMyBundle
:(
NSString
*
)
name
{
NSBundle
*
imageBundle
=
[
NSBundle
tz_imagePickerBundle
];
name
=
[
name
stringByAppendingString
:
@"@2x"
];
NSString
*
imagePath
=
[
imageBundle
pathForResource
:
name
ofType
:
@"png"
];
...
...
@@ -864,7 +863,7 @@
return
infoDict
?
infoDict
:
@{};
}
+
(
BOOL
)
tz_
isRightToLeftLayout
{
+
(
BOOL
)
isRightToLeftLayout
{
if
(
@available
(
iOS
9
.
0
,
*
))
{
if
([
UIView
userInterfaceLayoutDirectionForSemanticContentAttribute
:
UISemanticContentAttributeUnspecified
]
==
UIUserInterfaceLayoutDirectionRightToLeft
)
{
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 @@
@interface
TZLocationManager
:
NSObject
+
(
instancetype
)
manager
NS_SWIFT_NAME
(
default
())
;
+
(
instancetype
)
manager
;
/// 开始定位
-
(
void
)
startLocation
;
...
...
ios/TZImagePickerController/TZPhotoPickerController.m
View file @
81edf1ae
...
...
@@ -17,7 +17,6 @@
#import "TZGifPhotoPreviewController.h"
#import "TZLocationManager.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import "TZImageRequestOperation.h"
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
,
UIAlertViewDelegate
>
{
NSMutableArray
*
_models
;
...
...
@@ -39,11 +38,10 @@
@property
CGRect
previousPreheatRect
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
@property
(
nonatomic
,
strong
)
TZCollectionView
*
collectionView
;
@property
(
nonatomic
,
strong
)
UILabel
*
noDataLabel
;
@property
(
strong
,
nonatomic
)
UICollectionViewFlowLayout
*
layout
;
@property
(
nonatomic
,
strong
)
UIImagePickerController
*
imagePickerVc
;
@property
(
strong
,
nonatomic
)
CLLocation
*
location
;
@property
(
nonatomic
,
strong
)
NSOperationQueue
*
operationQueu
e
;
@property
(
assign
,
nonatomic
)
BOOL
useCachedImag
e
;
@end
static
CGSize
AssetGridThumbnailSize
;
...
...
@@ -95,9 +93,6 @@ static CGFloat itemMargin = 5;
_showTakePhotoBtn
=
_model
.
isCameraRoll
&&
((
tzImagePickerVc
.
allowTakePicture
&&
tzImagePickerVc
.
allowPickingImage
)
||
(
tzImagePickerVc
.
allowTakeVideo
&&
tzImagePickerVc
.
allowPickingVideo
));
// [self resetCachedAssets];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
didChangeStatusBarOrientationNotification
:
)
name
:
UIApplicationDidChangeStatusBarOrientationNotification
object
:
nil
];
self
.
operationQueue
=
[[
NSOperationQueue
alloc
]
init
];
self
.
operationQueue
.
maxConcurrentOperationCount
=
3
;
}
-
(
void
)
fetchAssetModels
{
...
...
@@ -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
);
}
else
{
_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
];
[
_collectionView
registerClass
:[
TZAssetCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCell"
];
...
...
@@ -225,7 +211,7 @@ static CGFloat itemMargin = 5;
if
(
tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
_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
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
[
_originalPhotoButton
setTitle
:
tzImagePickerVc
.
fullImageBtnTitleStr
forState
:
UIControlStateNormal
];
...
...
@@ -307,7 +293,6 @@ static CGFloat itemMargin = 5;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
toolBarHeight
:
self
.
view
.
tz_height
;
}
_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
;
_layout
.
itemSize
=
CGSizeMake
(
itemWH
,
itemWH
);
_layout
.
minimumInteritemSpacing
=
itemMargin
;
...
...
@@ -345,7 +330,6 @@ static CGFloat itemMargin = 5;
_divideLine
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
1
);
[
TZImageManager
manager
].
columnNumber
=
[
TZImageManager
manager
].
columnNumber
;
[
TZImageManager
manager
].
photoWidth
=
tzImagePickerVc
.
photoWidth
;
[
self
.
collectionView
reloadData
];
if
(
tzImagePickerVc
.
photoPickerPageDidLayoutSubviewsBlock
)
{
...
...
@@ -405,7 +389,7 @@ static CGFloat itemMargin = 5;
__block
UIAlertController
*
alertView
;
for
(
NSInteger
i
=
0
;
i
<
tzImagePickerVc
.
selectedModels
.
count
;
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
(
photo
)
{
if
(
!
[
TZImagePickerConfig
sharedInstance
].
notScaleImage
)
{
...
...
@@ -422,7 +406,7 @@ static CGFloat itemMargin = 5;
[
tzImagePickerVc
hideAlertView
:
alertView
];
[
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同步中,提醒用户
if
(
progress
<
1
&&
havenotShowAlert
&&
!
alertView
)
{
[
tzImagePickerVc
hideProgressHUD
];
...
...
@@ -433,8 +417,7 @@ static CGFloat itemMargin = 5;
if
(
progress
>=
1
)
{
havenotShowAlert
=
YES
;
}
}];
[
self
.
operationQueue
addOperation
:
operation
];
}
networkAccessAllowed
:
YES
];
}
}
if
(
tzImagePickerVc
.
selectedModels
.
count
<=
0
||
tzImagePickerVc
.
onlyReturnAsset
)
{
...
...
@@ -512,6 +495,7 @@ static CGFloat itemMargin = 5;
cell
.
allowPickingMultipleVideo
=
tzImagePickerVc
.
allowPickingMultipleVideo
;
cell
.
photoDefImage
=
tzImagePickerVc
.
photoDefImage
;
cell
.
photoSelImage
=
tzImagePickerVc
.
photoSelImage
;
cell
.
useCachedImage
=
self
.
useCachedImage
;
cell
.
assetCellDidSetModelBlock
=
tzImagePickerVc
.
assetCellDidSetModelBlock
;
cell
.
assetCellDidLayoutSubviewsBlock
=
tzImagePickerVc
.
assetCellDidLayoutSubviewsBlock
;
TZAssetModel
*
model
;
...
...
@@ -556,7 +540,7 @@ static CGFloat itemMargin = 5;
}
[
strongSelf
refreshBottomToolBarStatus
];
if
(
tzImagePickerVc
.
showSelectedIndex
||
tzImagePickerVc
.
showPhotoCannotSelectLayer
)
{
[
[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION"
object
:
strongSelf
.
navigationController
];
[
strongSelf
setUseCachedImageAndReloadData
];
}
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
}
else
{
...
...
@@ -570,10 +554,11 @@ static CGFloat itemMargin = 5;
}
strongCell
.
selectPhotoButton
.
selected
=
YES
;
model
.
isSelected
=
YES
;
[
tzImagePickerVc
addSelectedModel
:
model
];
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
];
[
UIView
showOscillatoryAnimationWithLayer
:
strongLayer
type
:
TZOscillatoryAnimationToSmaller
];
}
else
{
...
...
@@ -631,6 +616,14 @@ static CGFloat itemMargin = 5;
#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
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.h
View file @
81edf1ae
...
...
@@ -58,7 +58,6 @@
@property
(
strong
,
nonatomic
)
AVPlayerLayer
*
playerLayer
;
@property
(
strong
,
nonatomic
)
UIButton
*
playButton
;
@property
(
strong
,
nonatomic
)
UIImage
*
cover
;
@property
(
nonatomic
,
strong
)
NSURL
*
videoURL
;
-
(
void
)
pausePlayerAndShowNaviBar
;
@end
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.m
View file @
81edf1ae
...
...
@@ -224,8 +224,6 @@
self
.
imageRequestID
=
0
;
}
}
networkAccessAllowed
:
YES
];
[
self
configMaximumZoomScale
];
}
-
(
void
)
recoverSubviews
{
...
...
@@ -259,8 +257,9 @@
[
self
refreshScrollViewContentSize
];
}
-
(
void
)
configMaximumZoomScale
{
_scrollView
.
maximumZoomScale
=
_allowCrop
?
4
.
0
:
2
.
5
;
-
(
void
)
setAllowCrop
:
(
BOOL
)
allowCrop
{
_allowCrop
=
allowCrop
;
_scrollView
.
maximumZoomScale
=
allowCrop
?
4
.
0
:
2
.
5
;
if
([
self
.
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHAsset
*
phAsset
=
(
PHAsset
*
)
self
.
asset
;
...
...
@@ -355,7 +354,7 @@
@implementation
TZVideoPreviewCell
-
(
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
{
...
...
@@ -363,8 +362,8 @@
[
_playButton
removeFromSuperview
];
}
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
addSubview
:
_playButton
];
}
...
...
@@ -374,11 +373,6 @@
[
self
configMoviePlayer
];
}
-
(
void
)
setVideoURL
:
(
NSURL
*
)
videoURL
{
_videoURL
=
videoURL
;
[
self
configMoviePlayer
];
}
-
(
void
)
configMoviePlayer
{
if
(
_player
)
{
[
_playerLayer
removeFromSuperlayer
];
...
...
@@ -387,29 +381,20 @@
_player
=
nil
;
}
if
(
self
.
model
&&
self
.
model
.
asset
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
self
.
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
self
.
cover
=
photo
;
}];
[[
TZImageManager
manager
]
getVideoWithAsset
:
self
.
model
.
asset
completion
:
^
(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[
self
configPlayerWithItem
:
playerItem
];
});
}];
}
else
{
AVPlayerItem
*
playerItem
=
[
AVPlayerItem
playerItemWithURL
:
self
.
videoURL
];
[
self
configPlayerWithItem
:
playerItem
];
}
}
-
(
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
];
[[
TZImageManager
manager
]
getPhotoWithAsset
:
self
.
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
self
->
_cover
=
photo
;
}];
[[
TZImageManager
manager
]
getVideoWithAsset
:
self
.
model
.
asset
completion
:
^
(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
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
{
...
...
@@ -419,17 +404,7 @@
}
-
(
void
)
photoPreviewCollectionViewDidScroll
{
if
(
_player
&&
_player
.
rate
!=
0
.
0
)
{
[
self
pausePlayerAndShowNaviBar
];
}
}
#pragma mark - Notification
-
(
void
)
appWillResignActiveNotification
{
if
(
_player
&&
_player
.
rate
!=
0
.
0
)
{
[
self
pausePlayerAndShowNaviBar
];
}
[
self
pausePlayerAndShowNaviBar
];
}
#pragma mark - Click Event
...
...
@@ -451,10 +426,12 @@
}
-
(
void
)
pausePlayerAndShowNaviBar
{
[
_player
pause
];
[
_playButton
setImage
:[
UIImage
tz_imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
self
.
singleTapGestureBlock
)
{
self
.
singleTapGestureBlock
();
if
(
_player
.
rate
!=
0
.
0
)
{
[
_player
pause
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
self
.
singleTapGestureBlock
)
{
self
.
singleTapGestureBlock
();
}
}
}
...
...
ios/TZImagePickerController/TZPhotoPreviewController.m
View file @
81edf1ae
...
...
@@ -105,7 +105,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
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"navi_back"
]
forState
:
UIControlStateNormal
];
[
_backButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"navi_back"
]
forState
:
UIControlStateNormal
];
[
_backButton
setTitleColor
:[
UIColor
whiteColor
]
forState
:
UIControlStateNormal
];
[
_backButton
addTarget
:
self
action
:
@selector
(
backButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
...
...
@@ -137,7 +137,7 @@
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
_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
addTarget
:
self
action
:
@selector
(
originalPhotoButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
_originalPhotoButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
13
];
...
...
@@ -502,10 +502,7 @@
if
([
cell
isKindOfClass
:[
TZPhotoPreviewCell
class
]])
{
[(
TZPhotoPreviewCell
*
)
cell
recoverSubviews
];
}
else
if
([
cell
isKindOfClass
:[
TZVideoPreviewCell
class
]])
{
TZVideoPreviewCell
*
videoCell
=
(
TZVideoPreviewCell
*
)
cell
;
if
(
videoCell
.
player
&&
videoCell
.
player
.
rate
!=
0
.
0
)
{
[
videoCell
pausePlayerAndShowNaviBar
];
}
[(
TZVideoPreviewCell
*
)
cell
pausePlayerAndShowNaviBar
];
}
}
...
...
@@ -577,7 +574,7 @@
}
-
(
NSInteger
)
currentIndex
{
return
[
TZCommonTools
tz_
isRightToLeftLayout
]
?
self
.
models
.
count
-
_currentIndex
-
1
:
_currentIndex
;
return
[
TZCommonTools
isRightToLeftLayout
]
?
self
.
models
.
count
-
_currentIndex
-
1
:
_currentIndex
;
}
@end
ios/TZImagePickerController/TZVideoPlayerController.m
View file @
81edf1ae
...
...
@@ -93,8 +93,8 @@
-
(
void
)
configPlayButton
{
_playButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlayHL"
]
forState
:
UIControlStateHighlighted
];
[
_playButton
addTarget
:
self
action
:
@selector
(
playButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
_playButton
];
}
...
...
@@ -204,7 +204,7 @@
[
_player
pause
];
_toolBar
.
hidden
=
NO
;
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
_playButton
setImage
:[
UIImage
tz_
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
self
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
...
...
package.json
View file @
81edf1ae
{
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.3.
1
"
,
"version"
:
"0.3.
2
"
,
"description"
:
"React-Native 多图片选择 支持裁剪 压缩"
,
"main"
:
"index.js"
,
"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