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
37b14d5c
Commit
37b14d5c
authored
Oct 12, 2018
by
Syan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v0.1.8
parent
0a974a18
Changes
18
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
607 additions
and
1023 deletions
+607
-1023
README.md
README.md
+1
-1
index.js
index.js
+1
-0
RNSyanImagePicker.m
ios/RNSyanImagePicker.m
+20
-43
TZAssetCell.m
ios/TZImagePickerController/TZAssetCell.m
+5
-14
TZAssetModel.h
ios/TZImagePickerController/TZAssetModel.h
+7
-7
TZAssetModel.m
ios/TZImagePickerController/TZAssetModel.m
+4
-4
TZGifPhotoPreviewController.m
ios/TZImagePickerController/TZGifPhotoPreviewController.m
+13
-7
TZImageCropManager.m
ios/TZImagePickerController/TZImageCropManager.m
+1
-1
TZImageManager.h
ios/TZImagePickerController/TZImageManager.h
+30
-31
TZImageManager.m
ios/TZImagePickerController/TZImageManager.m
+306
-647
TZImagePickerController.h
ios/TZImagePickerController/TZImagePickerController.h
+16
-24
TZImagePickerController.m
ios/TZImagePickerController/TZImagePickerController.m
+74
-112
TZLocationManager.m
ios/TZImagePickerController/TZLocationManager.m
+1
-3
TZPhotoPickerController.m
ios/TZImagePickerController/TZPhotoPickerController.m
+75
-96
TZPhotoPreviewCell.m
ios/TZImagePickerController/TZPhotoPreviewCell.m
+7
-3
TZPhotoPreviewController.m
ios/TZImagePickerController/TZPhotoPreviewController.m
+34
-26
TZVideoPlayerController.m
ios/TZImagePickerController/TZVideoPlayerController.m
+11
-3
package.json
package.json
+1
-1
No files found.
README.md
View file @
37b14d5c
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
### 原生框架依赖
### 原生框架依赖
*
Android:
[
PictureSelector 2.2.3
](
https://github.com/LuckSiege/PictureSelector
)
- by
[
LuckSiege
](
https://github.com/LuckSiege
)
*
Android:
[
PictureSelector 2.2.3
](
https://github.com/LuckSiege/PictureSelector
)
- by
[
LuckSiege
](
https://github.com/LuckSiege
)
*
iOS:
[
TZImagePickerController
2.1.8
](
https://github.com/banchichen/TZImagePickerController
)
- by
[
banchichen
](
https://github.com/banchichen
)
*
iOS:
[
TZImagePickerController
3.0.9
](
https://github.com/banchichen/TZImagePickerController
)
- by
[
banchichen
](
https://github.com/banchichen
)
### 功能特点
### 功能特点
*
支持 iOS、Android 两端
*
支持 iOS、Android 两端
...
...
index.js
View file @
37b14d5c
...
@@ -23,6 +23,7 @@ const defaultOptions = {
...
@@ -23,6 +23,7 @@ const defaultOptions = {
showCropGrid
:
false
,
// 是否隐藏裁剪区域网格,默认false
showCropGrid
:
false
,
// 是否隐藏裁剪区域网格,默认false
quality
:
90
,
// 压缩质量
quality
:
90
,
// 压缩质量
enableBase64
:
false
,
// 是否返回base64编码,默认不返回
enableBase64
:
false
,
// 是否返回base64编码,默认不返回
allowPickingOriginalPhoto
:
false
};
};
export
default
{
export
default
{
...
...
ios/RNSyanImagePicker.m
View file @
37b14d5c
...
@@ -98,6 +98,7 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -98,6 +98,7 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
BOOL
isGif
=
[
self
.
cameraOptions
sy_boolForKey
:
@"isGif"
];
BOOL
isGif
=
[
self
.
cameraOptions
sy_boolForKey
:
@"isGif"
];
BOOL
showCropCircle
=
[
self
.
cameraOptions
sy_boolForKey
:
@"showCropCircle"
];
BOOL
showCropCircle
=
[
self
.
cameraOptions
sy_boolForKey
:
@"showCropCircle"
];
BOOL
isRecordSelected
=
[
self
.
cameraOptions
sy_boolForKey
:
@"isRecordSelected"
];
BOOL
isRecordSelected
=
[
self
.
cameraOptions
sy_boolForKey
:
@"isRecordSelected"
];
BOOL
allowPickingOriginalPhoto
=
[
self
.
cameraOptions
sy_boolForKey
:
@"allowPickingOriginalPhoto"
];
NSInteger
CropW
=
[
self
.
cameraOptions
sy_integerForKey
:
@"CropW"
];
NSInteger
CropW
=
[
self
.
cameraOptions
sy_integerForKey
:
@"CropW"
];
NSInteger
CropH
=
[
self
.
cameraOptions
sy_integerForKey
:
@"CropH"
];
NSInteger
CropH
=
[
self
.
cameraOptions
sy_integerForKey
:
@"CropH"
];
NSInteger
circleCropRadius
=
[
self
.
cameraOptions
sy_integerForKey
:
@"circleCropRadius"
];
NSInteger
circleCropRadius
=
[
self
.
cameraOptions
sy_integerForKey
:
@"circleCropRadius"
];
...
@@ -109,27 +110,22 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -109,27 +110,22 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
imagePickerVc
.
allowPickingGif
=
isGif
;
// 允许GIF
imagePickerVc
.
allowPickingGif
=
isGif
;
// 允许GIF
imagePickerVc
.
allowTakePicture
=
isCamera
;
// 允许用户在内部拍照
imagePickerVc
.
allowTakePicture
=
isCamera
;
// 允许用户在内部拍照
imagePickerVc
.
allowPickingVideo
=
NO
;
// 不允许视频
imagePickerVc
.
allowPickingVideo
=
NO
;
// 不允许视频
imagePickerVc
.
allowPickingOriginalPhoto
=
NO
;
// 允许原图
imagePickerVc
.
allowPickingOriginalPhoto
=
allowPickingOriginalPhoto
;
// 允许原图
imagePickerVc
.
alwaysEnableDoneBtn
=
YES
;
imagePickerVc
.
alwaysEnableDoneBtn
=
YES
;
imagePickerVc
.
allowCrop
=
isCrop
;
// 裁剪
imagePickerVc
.
allowCrop
=
isCrop
;
// 裁剪
if
(
isRecordSelected
)
{
imagePickerVc
.
selectedAssets
=
self
.
selectedAssets
;
// 当前已选中的图片
}
if
(
imageCount
==
1
)
{
if
(
imageCount
==
1
)
{
// 单选模式
// 单选模式
imagePickerVc
.
showSelectBtn
=
NO
;
imagePickerVc
.
showSelectBtn
=
NO
;
imagePickerVc
.
allowPreview
=
NO
;
if
(
isCrop
){
if
(
isCrop
){
if
(
showCropCircle
)
{
if
(
showCropCircle
)
{
imagePickerVc
.
needCircleCrop
=
showCropCircle
;
//圆形裁剪
imagePickerVc
.
needCircleCrop
=
showCropCircle
;
//圆形裁剪
imagePickerVc
.
circleCropRadius
=
circleCropRadius
;
//圆形半径
imagePickerVc
.
circleCropRadius
=
circleCropRadius
/
2
;
//圆形半径
}
else
{
}
else
{
CGFloat
x
=
([[
UIScreen
mainScreen
]
bounds
].
size
.
width
-
CropW
)
/
2
;
CGFloat
x
=
([[
UIScreen
mainScreen
]
bounds
].
size
.
width
-
CropW
)
/
2
;
CGFloat
y
=
([[
UIScreen
mainScreen
]
bounds
].
size
.
height
-
CropH
)
/
2
;
CGFloat
y
=
([[
UIScreen
mainScreen
]
bounds
].
size
.
height
-
CropH
)
/
2
;
imagePickerVc
.
cropRect
=
imagePickerVc
.
cropRect
=
CGRectMake
(
x
,
y
,
CropW
,
CropH
);
imagePickerVc
.
cropRect
=
CGRectMake
(
x
,
y
,
CropW
,
CropH
);
}
}
}
}
}
}
...
@@ -172,38 +168,24 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -172,38 +168,24 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
#pragma mark - UIImagePickerController
#pragma mark - UIImagePickerController
-
(
void
)
takePhoto
{
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
if
(
(
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
&&
iOS7Later
)
{
if
(
authStatus
==
AVAuthorizationStatusRestricted
||
authStatus
==
AVAuthorizationStatusDenied
)
{
// 无相机权限 做一个友好的提示
// 无相机权限 做一个友好的提示
if
(
iOS8Later
)
{
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法使用相机"
message
:
@"请在iPhone的""设置-隐私-相机""中允许访问相机"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法使用相机"
message
:
@"请在iPhone的""设置-隐私-相机""中允许访问相机"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
[
alert
show
];
[
alert
show
];
}
else
{
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法使用相机"
message
:
@"请在iPhone的""设置-隐私-相机""中允许访问相机"
delegate
:
self
cancelButtonTitle
:
@"确定"
otherButtonTitles
:
nil
];
[
alert
show
];
}
}
else
if
(
authStatus
==
AVAuthorizationStatusNotDetermined
)
{
}
else
if
(
authStatus
==
AVAuthorizationStatusNotDetermined
)
{
// fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
// fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
if
(
iOS7Later
)
{
[
AVCaptureDevice
requestAccessForMediaType
:
AVMediaTypeVideo
completionHandler
:
^
(
BOOL
granted
)
{
[
AVCaptureDevice
requestAccessForMediaType
:
AVMediaTypeVideo
completionHandler
:
^
(
BOOL
granted
)
{
if
(
granted
)
{
if
(
granted
)
{
dispatch_
sync
(
dispatch_get_main_queue
(),
^
{
dispatch_a
sync
(
dispatch_get_main_queue
(),
^
{
[
self
takePhoto
];
[
self
takePhoto
];
});
});
}
}
}];
}];
}
else
{
[
self
takePhoto
];
}
// 拍照之前还需要检查相册权限
// 拍照之前还需要检查相册权限
}
else
if
([
TZImageManager
authorizationStatus
]
==
2
)
{
// 已被拒绝,没有相册权限,将无法保存拍的照片
}
else
if
([
PHPhotoLibrary
authorizationStatus
]
==
2
)
{
// 已被拒绝,没有相册权限,将无法保存拍的照片
if
(
iOS8Later
)
{
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法访问相册"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法访问相册"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"设置"
,
nil
];
[
alert
show
];
[
alert
show
];
}
else
{
}
else
if
([
PHPhotoLibrary
authorizationStatus
]
==
0
)
{
// 未请求过相册权限
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"无法访问相册"
message
:
@"请在iPhone的""设置-隐私-相册""中允许访问相册"
delegate
:
self
cancelButtonTitle
:
@"确定"
otherButtonTitles
:
nil
];
[
alert
show
];
}
}
else
if
([
TZImageManager
authorizationStatus
]
==
0
)
{
// 未请求过相册权限
[[
TZImageManager
manager
]
requestAuthorizationWithCompletion
:
^
{
[[
TZImageManager
manager
]
requestAuthorizationWithCompletion
:
^
{
[
self
takePhoto
];
[
self
takePhoto
];
}];
}];
...
@@ -217,9 +199,6 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -217,9 +199,6 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
self
.
imagePickerVc
.
sourceType
=
sourceType
;
self
.
imagePickerVc
.
sourceType
=
sourceType
;
if
(
iOS8Later
)
{
self
.
imagePickerVc
.
modalPresentationStyle
=
UIModalPresentationOverCurrentContext
;
}
[[
self
topViewController
]
presentViewController
:
self
.
imagePickerVc
animated
:
YES
completion
:
nil
];
[[
self
topViewController
]
presentViewController
:
self
.
imagePickerVc
animated
:
YES
completion
:
nil
];
}
else
{
}
else
{
NSLog
(
@"模拟器中无法打开照相机,请在真机中使用"
);
NSLog
(
@"模拟器中无法打开照相机,请在真机中使用"
);
...
@@ -237,7 +216,7 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -237,7 +216,7 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerOriginalImage
];
// save photo and get asset / 保存图片,获取到asset
// save photo and get asset / 保存图片,获取到asset
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
location
:
NULL
completion
:^
(
NSError
*
error
){
[[
TZImageManager
manager
]
savePhotoWithImage
:
image
location
:
NULL
completion
:^
(
PHAsset
*
asset
,
NSError
*
error
){
if
(
error
)
{
if
(
error
)
{
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
NSLog
(
@"图片保存失败 %@"
,
error
);
NSLog
(
@"图片保存失败 %@"
,
error
);
...
@@ -289,10 +268,8 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
...
@@ -289,10 +268,8 @@ RCT_EXPORT_METHOD(removeAllPhoto) {
#pragma mark - UIAlertViewDelegate
#pragma mark - UIAlertViewDelegate
-
(
void
)
alertView
:
(
UIAlertView
*
)
alertView
clickedButtonAtIndex
:
(
NSInteger
)
buttonIndex
{
-
(
void
)
alertView
:
(
UIAlertView
*
)
alertView
clickedButtonAtIndex
:
(
NSInteger
)
buttonIndex
{
if
(
buttonIndex
==
1
)
{
// 去设置界面,开启相机访问权限
if
(
buttonIndex
==
1
)
{
// 去设置界面,开启相机访问权限
if
(
iOS8Later
)
{
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
[[
UIApplication
sharedApplication
]
openURL
:[
NSURL
URLWithString
:
UIApplicationOpenSettingsURLString
]];
}
}
}
}
}
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
quality
:
(
NSInteger
)
quality
{
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
quality
:
(
NSInteger
)
quality
{
...
...
ios/TZImagePickerController/TZAssetCell.m
View file @
37b14d5c
...
@@ -30,22 +30,14 @@
...
@@ -30,22 +30,14 @@
-
(
void
)
setModel
:(
TZAssetModel
*
)
model
{
-
(
void
)
setModel
:(
TZAssetModel
*
)
model
{
_model
=
model
;
_model
=
model
;
if
(
iOS8Later
)
{
self
.
representedAssetIdentifier
=
model
.
asset
.
localIdentifier
;
self
.
representedAssetIdentifier
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
}
if
(
self
.
useCachedImage
&&
model
.
cachedImage
)
{
if
(
self
.
useCachedImage
&&
model
.
cachedImage
)
{
self
.
imageView
.
image
=
model
.
cachedImage
;
self
.
imageView
.
image
=
model
.
cachedImage
;
}
else
{
}
else
{
self
.
model
.
cachedImage
=
nil
;
self
.
model
.
cachedImage
=
nil
;
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
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.
// Set the cell's thumbnail image if it's still showing the same asset.
if
(
!
iOS8Later
)
{
if
([
self
.
representedAssetIdentifier
isEqualToString
:
model
.
asset
.
localIdentifier
])
{
self
.
imageView
.
image
=
photo
;
self
.
model
.
cachedImage
=
photo
;
[
self
hideProgressView
];
return
;
}
if
([
self
.
representedAssetIdentifier
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]])
{
self
.
imageView
.
image
=
photo
;
self
.
imageView
.
image
=
photo
;
self
.
model
.
cachedImage
=
photo
;
self
.
model
.
cachedImage
=
photo
;
}
else
{
}
else
{
...
@@ -383,10 +375,9 @@
...
@@ -383,10 +375,9 @@
}
}
}
}
/// For fitting iOS6
-
(
void
)
layoutSubviews
{
-
(
void
)
layoutSubviews
{
if
(
iOS7Later
)
[
super
layoutSubviews
];
[
super
layoutSubviews
];
_selectedCountButton
.
frame
=
CGRectMake
(
self
.
tz_width
-
24
-
30
,
23
,
24
,
24
);
_selectedCountButton
.
frame
=
CGRectMake
(
self
.
contentView
.
tz_width
-
24
,
23
,
24
,
24
);
NSInteger
titleHeight
=
ceil
(
self
.
titleLabel
.
font
.
lineHeight
);
NSInteger
titleHeight
=
ceil
(
self
.
titleLabel
.
font
.
lineHeight
);
self
.
titleLabel
.
frame
=
CGRectMake
(
80
,
(
self
.
tz_height
-
titleHeight
)
/
2
,
self
.
tz_width
-
80
-
50
,
titleHeight
);
self
.
titleLabel
.
frame
=
CGRectMake
(
80
,
(
self
.
tz_height
-
titleHeight
)
/
2
,
self
.
tz_width
-
80
-
50
,
titleHeight
);
self
.
posterImageView
.
frame
=
CGRectMake
(
0
,
0
,
70
,
70
);
self
.
posterImageView
.
frame
=
CGRectMake
(
0
,
0
,
70
,
70
);
...
@@ -397,7 +388,7 @@
...
@@ -397,7 +388,7 @@
}
}
-
(
void
)
layoutSublayersOfLayer
:
(
CALayer
*
)
layer
{
-
(
void
)
layoutSublayersOfLayer
:
(
CALayer
*
)
layer
{
if
(
iOS7Later
)
[
super
layoutSublayersOfLayer
:
layer
];
[
super
layoutSublayersOfLayer
:
layer
];
}
}
#pragma mark - Lazy load
#pragma mark - Lazy load
...
...
ios/TZImagePickerController/TZAssetModel.h
View file @
37b14d5c
...
@@ -20,17 +20,17 @@ typedef enum : NSUInteger {
...
@@ -20,17 +20,17 @@ typedef enum : NSUInteger {
@class
PHAsset
;
@class
PHAsset
;
@interface
TZAssetModel
:
NSObject
@interface
TZAssetModel
:
NSObject
@property
(
nonatomic
,
strong
)
id
asset
;
///< PHAsset or ALAsset
@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
(
assign
,
nonatomic
)
BOOL
needOscillatoryAnimation
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
strong
,
nonatomic
)
UIImage
*
cachedImage
;
@property
(
strong
,
nonatomic
)
UIImage
*
cachedImage
;
/// Init a photo dataModel With a
a
sset
/// Init a photo dataModel With a
PHA
sset
/// 用一个PHAsset
/ALAsset
实例,初始化一个照片模型
/// 用一个PHAsset实例,初始化一个照片模型
+
(
instancetype
)
modelWithAsset
:(
id
)
asset
type
:(
TZAssetModelMediaType
)
type
;
+
(
instancetype
)
modelWithAsset
:(
PHAsset
*
)
asset
type
:(
TZAssetModelMediaType
)
type
;
+
(
instancetype
)
modelWithAsset
:(
id
)
asset
type
:(
TZAssetModelMediaType
)
type
timeLength
:(
NSString
*
)
timeLength
;
+
(
instancetype
)
modelWithAsset
:(
PHAsset
*
)
asset
type
:(
TZAssetModelMediaType
)
type
timeLength
:(
NSString
*
)
timeLength
;
@end
@end
...
@@ -40,7 +40,7 @@ typedef enum : NSUInteger {
...
@@ -40,7 +40,7 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
strong
)
NSString
*
name
;
///< The album name
@property
(
nonatomic
,
strong
)
NSString
*
name
;
///< The album name
@property
(
nonatomic
,
assign
)
NSInteger
count
;
///< Count of photos the album contain
@property
(
nonatomic
,
assign
)
NSInteger
count
;
///< Count of photos the album contain
@property
(
nonatomic
,
strong
)
id
result
;
///< PHFetchResult<PHAsset> or ALAssetsGroup<ALAsset>
@property
(
nonatomic
,
strong
)
PHFetchResult
*
result
;
@property
(
nonatomic
,
strong
)
NSArray
*
models
;
@property
(
nonatomic
,
strong
)
NSArray
*
models
;
@property
(
nonatomic
,
strong
)
NSArray
*
selectedModels
;
@property
(
nonatomic
,
strong
)
NSArray
*
selectedModels
;
...
@@ -48,6 +48,6 @@ typedef enum : NSUInteger {
...
@@ -48,6 +48,6 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
assign
)
BOOL
isCameraRoll
;
@property
(
nonatomic
,
assign
)
BOOL
isCameraRoll
;
-
(
void
)
setResult
:(
id
)
result
needFetchAssets
:(
BOOL
)
needFetchAssets
;
-
(
void
)
setResult
:(
PHFetchResult
*
)
result
needFetchAssets
:(
BOOL
)
needFetchAssets
;
@end
@end
ios/TZImagePickerController/TZAssetModel.m
View file @
37b14d5c
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
@implementation
TZAssetModel
@implementation
TZAssetModel
+
(
instancetype
)
modelWithAsset
:(
id
)
asset
type
:(
TZAssetModelMediaType
)
type
{
+
(
instancetype
)
modelWithAsset
:(
PHAsset
*
)
asset
type
:(
TZAssetModelMediaType
)
type
{
TZAssetModel
*
model
=
[[
TZAssetModel
alloc
]
init
];
TZAssetModel
*
model
=
[[
TZAssetModel
alloc
]
init
];
model
.
asset
=
asset
;
model
.
asset
=
asset
;
model
.
isSelected
=
NO
;
model
.
isSelected
=
NO
;
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
return
model
;
return
model
;
}
}
+
(
instancetype
)
modelWithAsset
:(
id
)
asset
type
:(
TZAssetModelMediaType
)
type
timeLength
:(
NSString
*
)
timeLength
{
+
(
instancetype
)
modelWithAsset
:(
PHAsset
*
)
asset
type
:(
TZAssetModelMediaType
)
type
timeLength
:(
NSString
*
)
timeLength
{
TZAssetModel
*
model
=
[
self
modelWithAsset
:
asset
type
:
type
];
TZAssetModel
*
model
=
[
self
modelWithAsset
:
asset
type
:
type
];
model
.
timeLength
=
timeLength
;
model
.
timeLength
=
timeLength
;
return
model
;
return
model
;
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
@implementation
TZAlbumModel
@implementation
TZAlbumModel
-
(
void
)
setResult
:(
id
)
result
needFetchAssets
:(
BOOL
)
needFetchAssets
{
-
(
void
)
setResult
:(
PHFetchResult
*
)
result
needFetchAssets
:(
BOOL
)
needFetchAssets
{
_result
=
result
;
_result
=
result
;
if
(
needFetchAssets
)
{
if
(
needFetchAssets
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
result
completion
:
^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
result
completion
:
^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
[
selectedAssets
addObject
:
model
.
asset
];
[
selectedAssets
addObject
:
model
.
asset
];
}
}
for
(
TZAssetModel
*
model
in
_models
)
{
for
(
TZAssetModel
*
model
in
_models
)
{
if
([
[
TZImageManager
manager
]
isAssetsArray
:
selectedAssets
containAsse
t
:
model
.
asset
])
{
if
([
selectedAssets
containsObjec
t
:
model
.
asset
])
{
self
.
selectedCount
++
;
self
.
selectedCount
++
;
}
}
}
}
...
...
ios/TZImagePickerController/TZGifPhotoPreviewController.m
View file @
37b14d5c
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
_originStatusBarStyle
=
[
UIApplication
sharedApplication
].
statusBarStyle
;
_originStatusBarStyle
=
[
UIApplication
sharedApplication
].
statusBarStyle
;
[
UIApplication
sharedApplication
].
statusBarStyle
=
iOS7Later
?
UIStatusBarStyleLightContent
:
UIStatusBarStyleBlackOpaque
;
[
UIApplication
sharedApplication
].
statusBarStyle
=
UIStatusBarStyleLightContent
;
}
}
-
(
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
...
@@ -96,6 +96,14 @@
...
@@ -96,6 +96,14 @@
}
}
}
}
-
(
UIStatusBarStyle
)
preferredStatusBarStyle
{
TZImagePickerController
*
tzImagePicker
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePicker
&&
[
tzImagePicker
isKindOfClass
:[
TZImagePickerController
class
]])
{
return
tzImagePicker
.
statusBarStyle
;
}
return
[
super
preferredStatusBarStyle
];
}
#pragma mark - Layout
#pragma mark - Layout
-
(
void
)
viewDidLayoutSubviews
{
-
(
void
)
viewDidLayoutSubviews
{
...
@@ -119,13 +127,11 @@
...
@@ -119,13 +127,11 @@
_toolBar
.
hidden
=
!
_toolBar
.
isHidden
;
_toolBar
.
hidden
=
!
_toolBar
.
isHidden
;
[
self
.
navigationController
setNavigationBarHidden
:
_toolBar
.
isHidden
];
[
self
.
navigationController
setNavigationBarHidden
:
_toolBar
.
isHidden
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
iOS7Later
)
{
if
(
_toolBar
.
isHidden
)
{
if
(
_toolBar
.
isHidden
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
else
if
(
tzImagePickerVc
.
needShowStatusBar
)
{
}
else
if
(
tzImagePickerVc
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
}
}
}
-
(
void
)
doneButtonClick
{
-
(
void
)
doneButtonClick
{
...
...
ios/TZImagePickerController/TZImageCropManager.m
View file @
37b14d5c
...
@@ -133,7 +133,7 @@
...
@@ -133,7 +133,7 @@
}
}
else
{
else
{
// images数组过大时内存会飙升,在这里限制下最大count
// images数组过大时内存会飙升,在这里限制下最大count
NSInteger
maxCount
=
[
TZImagePickerConfig
sharedInstance
].
gifPreviewMaxImagesCount
?:
20
0
;
NSInteger
maxCount
=
[
TZImagePickerConfig
sharedInstance
].
gifPreviewMaxImagesCount
?:
5
0
;
NSInteger
interval
=
MAX
((
count
+
maxCount
/
2
)
/
maxCount
,
1
);
NSInteger
interval
=
MAX
((
count
+
maxCount
/
2
)
/
maxCount
,
1
);
NSMutableArray
*
images
=
[
NSMutableArray
array
];
NSMutableArray
*
images
=
[
NSMutableArray
array
];
...
...
ios/TZImagePickerController/TZImageManager.h
View file @
37b14d5c
...
@@ -46,7 +46,6 @@
...
@@ -46,7 +46,6 @@
/// Return YES if Authorized 返回YES如果得到了授权
/// Return YES if Authorized 返回YES如果得到了授权
-
(
BOOL
)
authorizationStatusAuthorized
;
-
(
BOOL
)
authorizationStatusAuthorized
;
+
(
NSInteger
)
authorizationStatus
;
-
(
void
)
requestAuthorizationWithCompletion
:(
void
(
^
)(
void
))
completion
;
-
(
void
)
requestAuthorizationWithCompletion
:(
void
(
^
)(
void
))
completion
;
/// Get Album 获得相册/相册数组
/// Get Album 获得相册/相册数组
...
@@ -54,68 +53,68 @@
...
@@ -54,68 +53,68 @@
-
(
void
)
getAllAlbums
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
needFetchAssets
:(
BOOL
)
needFetchAssets
completion
:(
void
(
^
)(
NSArray
<
TZAlbumModel
*>
*
models
))
completion
;
-
(
void
)
getAllAlbums
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
needFetchAssets
:(
BOOL
)
needFetchAssets
completion
:(
void
(
^
)(
NSArray
<
TZAlbumModel
*>
*
models
))
completion
;
/// Get Assets 获得Asset数组
/// Get Assets 获得Asset数组
-
(
void
)
getAssetsFromFetchResult
:(
id
)
result
completion
:(
void
(
^
)(
NSArray
<
TZAssetModel
*>
*
models
))
completion
;
-
(
void
)
getAssetsFromFetchResult
:(
PHFetchResult
*
)
result
completion
:(
void
(
^
)(
NSArray
<
TZAssetModel
*>
*
models
))
completion
;
-
(
void
)
getAssetsFromFetchResult
:(
id
)
result
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
NSArray
<
TZAssetModel
*>
*
models
))
completion
;
-
(
void
)
getAssetsFromFetchResult
:(
PHFetchResult
*
)
result
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
NSArray
<
TZAssetModel
*>
*
models
))
completion
;
-
(
void
)
getAssetFromFetchResult
:(
id
)
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 获得照片
-
(
void
)
getPostImageWithAlbumModel
:(
TZAlbumModel
*
)
model
completion
:(
void
(
^
)(
UIImage
*
postImage
))
completion
;
-
(
void
)
getPostImageWithAlbumModel
:(
TZAlbumModel
*
)
model
completion
:(
void
(
^
)(
UIImage
*
postImage
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
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
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
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
;
-
(
int32_t
)
getPhotoWithAsset
:(
id
)
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
;
-
(
int32_t
)
requestImageDataForAsset
:(
id
)
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,则表明当前返回的是缩略图,否则是原图。
-
(
void
)
getOriginalPhotoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
id
)
asset
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoWithAsset
:(
PHAsset
*
)
asset
newCompletion
:(
void
(
^
)(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
// 该方法中,completion只会走一次
// 该方法中,completion只会走一次
-
(
void
)
getOriginalPhotoDataWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoDataWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSData
*
data
,
NSDictionary
*
info
,
BOOL
isDegraded
))
completion
;
-
(
void
)
getOriginalPhotoDataWithAsset
:(
id
)
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
(
^
)(
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
NSError
*
error
))
completion
;
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
/// Save video 保存视频
/// Save video 保存视频
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
NSError
*
error
))
completion
;
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
NSError
*
error
))
completion
;
-
(
void
)
saveVideoWithUrl
:(
NSURL
*
)
url
location
:(
CLLocation
*
)
location
completion
:(
void
(
^
)(
PHAsset
*
asset
,
NSError
*
error
))
completion
;
/// Get video 获得视频
/// Get video 获得视频
-
(
void
)
getVideoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getVideoWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
))
completion
;
-
(
void
)
getVideoWithAsset
:(
id
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
AVPlayerItem
*
,
NSDictionary
*
))
completion
;
-
(
void
)
getVideoWithAsset
:(
PHAsset
*
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
AVPlayerItem
*
,
NSDictionary
*
))
completion
;
/// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480
/// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
-
(
void
)
getVideoOutputPathWithAsset
:(
PHAsset
*
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
presetName
:(
NSString
*
)
presetName
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
-
(
void
)
getVideoOutputPathWithAsset
:(
PHAsset
*
)
asset
presetName
:(
NSString
*
)
presetName
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
__attribute__
((
deprecated
(
"Use -getVideoOutputPathWithAsset:failure:success:"
)));
-
(
void
)
getVideoOutputPathWithAsset
:(
PHAsset
*
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
__attribute__
((
deprecated
(
"Use -getVideoOutputPathWithAsset:failure:success:"
)));
/// Get photo bytes 获得一组照片的大小
/// Get photo bytes 获得一组照片的大小
-
(
void
)
getPhotosBytesWithArray
:(
NSArray
*
)
photos
completion
:(
void
(
^
)(
NSString
*
totalBytes
))
completion
;
-
(
void
)
getPhotosBytesWithArray
:(
NSArray
*
)
photos
completion
:(
void
(
^
)(
NSString
*
totalBytes
))
completion
;
/// Judge is a assets array contain the asset 判断一个assets数组是否包含这个asset
-
(
BOOL
)
isCameraRollAlbum
:(
PHAssetCollection
*
)
metadata
;
-
(
BOOL
)
isAssetsArray
:(
NSArray
*
)
assets
containAsset
:(
id
)
asset
;
-
(
NSString
*
)
getAssetIdentifier
:(
id
)
asset
;
-
(
BOOL
)
isCameraRollAlbum
:(
id
)
metadata
;
/// 检查照片大小是否满足最小要求
/// 检查照片大小是否满足最小要求
-
(
BOOL
)
isPhotoSelectableWithAsset
:(
id
)
asset
;
-
(
BOOL
)
isPhotoSelectableWithAsset
:(
PHAsset
*
)
asset
;
-
(
CGSize
)
photoSizeWithAsset
:(
id
)
asset
;
/// 修正图片转向
/// 修正图片转向
-
(
UIImage
*
)
fixOrientation
:(
UIImage
*
)
aImage
;
-
(
UIImage
*
)
fixOrientation
:(
UIImage
*
)
aImage
;
/// 获取asset的资源类型
/// 获取asset的资源类型
-
(
TZAssetModelMediaType
)
getAssetType
:(
id
)
asset
;
-
(
TZAssetModelMediaType
)
getAssetType
:(
PHAsset
*
)
asset
;
/// 缩放图片至新尺寸
/// 缩放图片至新尺寸
-
(
UIImage
*
)
scaleImage
:(
UIImage
*
)
image
toSize
:(
CGSize
)
size
;
-
(
UIImage
*
)
scaleImage
:(
UIImage
*
)
image
toSize
:(
CGSize
)
size
;
/// 判断asset是否是视频
/// 判断asset是否是视频
-
(
BOOL
)
isVideo
:(
id
)
asset
;
-
(
BOOL
)
isVideo
:(
PHAsset
*
)
asset
;
/// for TZImagePreviewController
-
(
NSString
*
)
getNewTimeFromDurationSecond
:(
NSInteger
)
duration
;
-
(
TZAssetModel
*
)
createModelWithAsset
:(
PHAsset
*
)
asset
;
@end
@end
...
...
ios/TZImagePickerController/TZImageManager.m
View file @
37b14d5c
This diff is collapsed.
Click to expand it.
ios/TZImagePickerController/TZImagePickerController.h
View file @
37b14d5c
...
@@ -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
2.2.6 - 2018.08.21
// version
3.0.9 - 2018.10.09
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
/*
/*
...
@@ -24,9 +24,7 @@
...
@@ -24,9 +24,7 @@
#import "TZGifPhotoPreviewController.h"
#import "TZGifPhotoPreviewController.h"
#import "TZLocationManager.h"
#import "TZLocationManager.h"
#import "TZPhotoPreviewController.h"
#import "TZPhotoPreviewController.h"
#import "TZPhotoPreviewCell.h"
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
@class
TZAlbumCell
,
TZAssetCell
;
@class
TZAlbumCell
,
TZAssetCell
;
@
protocol
TZImagePickerControllerDelegate
;
@
protocol
TZImagePickerControllerDelegate
;
...
@@ -40,7 +38,7 @@
...
@@ -40,7 +38,7 @@
/// This init method just for previewing photos / 用这个初始化方法以预览图片
/// This init method just for previewing photos / 用这个初始化方法以预览图片
-
(
instancetype
)
initWithSelectedAssets
:(
NSMutableArray
*
)
selectedAssets
selectedPhotos
:(
NSMutableArray
*
)
selectedPhotos
index
:(
NSInteger
)
index
;
-
(
instancetype
)
initWithSelectedAssets
:(
NSMutableArray
*
)
selectedAssets
selectedPhotos
:(
NSMutableArray
*
)
selectedPhotos
index
:(
NSInteger
)
index
;
/// This init method for crop photo / 用这个初始化方法以裁剪图片
/// This init method for crop photo / 用这个初始化方法以裁剪图片
-
(
instancetype
)
initCropTypeWithAsset
:(
id
)
asset
photo
:(
UIImage
*
)
photo
completion
:(
void
(
^
)(
UIImage
*
cropImage
,
id
asset
))
completion
;
-
(
instancetype
)
initCropTypeWithAsset
:(
PHAsset
*
)
asset
photo
:(
UIImage
*
)
photo
completion
:(
void
(
^
)(
UIImage
*
cropImage
,
PHAsset
*
asset
))
completion
;
#pragma mark -
#pragma mark -
/// Default is 9 / 默认最大可选9张图片
/// Default is 9 / 默认最大可选9张图片
...
@@ -185,8 +183,8 @@
...
@@ -185,8 +183,8 @@
@property
(
nonatomic
,
copy
)
void
(
^
albumCellDidLayoutSubviewsBlock
)(
TZAlbumCell
*
cell
,
UIImageView
*
posterImageView
,
UILabel
*
titleLabel
);
@property
(
nonatomic
,
copy
)
void
(
^
albumCellDidLayoutSubviewsBlock
)(
TZAlbumCell
*
cell
,
UIImageView
*
posterImageView
,
UILabel
*
titleLabel
);
#pragma mark -
#pragma mark -
-
(
id
)
showAlertWithTitle
:(
NSString
*
)
title
;
-
(
UIAlertController
*
)
showAlertWithTitle
:(
NSString
*
)
title
;
-
(
void
)
hideAlertView
:(
id
)
alertView
;
-
(
void
)
hideAlertView
:(
UIAlertController
*
)
alertView
;
-
(
void
)
showProgressHUD
;
-
(
void
)
showProgressHUD
;
-
(
void
)
hideProgressHUD
;
-
(
void
)
hideProgressHUD
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
...
@@ -247,10 +245,8 @@
...
@@ -247,10 +245,8 @@
@property
(
nonatomic
,
copy
)
void
(
^
imagePickerControllerDidCancelHandle
)(
void
);
@property
(
nonatomic
,
copy
)
void
(
^
imagePickerControllerDidCancelHandle
)(
void
);
// If user picking a video, this handle will be called.
// If user picking a video, this handle will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
// 如果用户选择了一个视频,下面的handle会被执行
// 如果用户选择了一个视频,下面的handle会被执行
// 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingVideoHandle
)(
UIImage
*
coverImage
,
PHAsset
*
asset
);
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingVideoHandle
)(
UIImage
*
coverImage
,
id
asset
);
// If user picking a gif image, this callback will be called.
// If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行
// 如果用户选择了一个gif图片,下面的handle会被执行
...
@@ -279,22 +275,20 @@
...
@@ -279,22 +275,20 @@
-
(
void
)
tz_imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
-
(
void
)
tz_imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
// If user picking a video, this callback will be called.
// If user picking a video, this callback will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
// 如果用户选择了一个视频,下面的handle会被执行
// 如果用户选择了一个视频,下面的handle会被执行
// 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingVideo
:(
UIImage
*
)
coverImage
sourceAssets
:(
PHAsset
*
)
asset
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingVideo
:(
UIImage
*
)
coverImage
sourceAssets
:(
id
)
asset
;
// If user picking a gif image, this callback will be called.
// If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行
// 如果用户选择了一个gif图片,下面的handle会被执行
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingGifImage
:(
UIImage
*
)
animatedImage
sourceAssets
:(
id
)
asset
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingGifImage
:(
UIImage
*
)
animatedImage
sourceAssets
:(
PHAsset
*
)
asset
;
// Decide album show or not't
// Decide album show or not't
// 决定相册显示与否 albumName:相册名字 result:相册原始数据
// 决定相册显示与否 albumName:相册名字 result:相册原始数据
-
(
BOOL
)
isAlbumCanSelect
:(
NSString
*
)
albumName
result
:(
id
)
result
;
-
(
BOOL
)
isAlbumCanSelect
:(
NSString
*
)
albumName
result
:(
PHFetchResult
*
)
result
;
// Decide asset show or not't
// Decide asset show or not't
// 决定照片显示与否
// 决定照片显示与否
-
(
BOOL
)
isAssetCanSelect
:(
id
)
asset
;
-
(
BOOL
)
isAssetCanSelect
:(
PHAsset
*
)
asset
;
@end
@end
...
@@ -310,17 +304,12 @@
...
@@ -310,17 +304,12 @@
@end
@end
@interface
NSString
(
TzExtension
)
-
(
BOOL
)
tz_containsString
:(
NSString
*
)
string
;
-
(
CGSize
)
tz_calculateSizeWithAttributes
:(
NSDictionary
*
)
attributes
maxSize
:(
CGSize
)
maxSize
;
@end
@interface
TZCommonTools
:
NSObject
@interface
TZCommonTools
:
NSObject
+
(
BOOL
)
tz_isIPhoneX
;
+
(
BOOL
)
tz_isIPhoneX
;
+
(
CGFloat
)
tz_statusBarHeight
;
+
(
CGFloat
)
tz_statusBarHeight
;
// 获得Info.plist数据字典
// 获得Info.plist数据字典
+
(
NSDictionary
*
)
tz_getInfoDictionary
;
+
(
NSDictionary
*
)
tz_getInfoDictionary
;
+
(
BOOL
)
isRightToLeftLayout
;
@end
@end
...
@@ -330,10 +319,13 @@
...
@@ -330,10 +319,13 @@
@property
(
nonatomic
,
assign
)
BOOL
allowPickingImage
;
@property
(
nonatomic
,
assign
)
BOOL
allowPickingImage
;
@property
(
nonatomic
,
assign
)
BOOL
allowPickingVideo
;
@property
(
nonatomic
,
assign
)
BOOL
allowPickingVideo
;
@property
(
strong
,
nonatomic
)
NSBundle
*
languageBundle
;
@property
(
strong
,
nonatomic
)
NSBundle
*
languageBundle
;
/// 默认是200,如果一个GIF过大,里面图片个数可能超过1000,会导致内存飙升而崩溃
@property
(
assign
,
nonatomic
)
NSInteger
gifPreviewMaxImagesCount
;
@property
(
assign
,
nonatomic
)
BOOL
showSelectedIndex
;
@property
(
assign
,
nonatomic
)
BOOL
showSelectedIndex
;
@property
(
assign
,
nonatomic
)
BOOL
showPhotoCannotSelectLayer
;
@property
(
assign
,
nonatomic
)
BOOL
showPhotoCannotSelectLayer
;
@property
(
assign
,
nonatomic
)
BOOL
notScaleImage
;
@property
(
assign
,
nonatomic
)
BOOL
notScaleImage
;
@property
(
assign
,
nonatomic
)
BOOL
needFixComposition
;
@property
(
assign
,
nonatomic
)
BOOL
needFixComposition
;
/// 默认是50,如果一个GIF过大,里面图片个数可能超过1000,会导致内存飙升而崩溃
@property
(
assign
,
nonatomic
)
NSInteger
gifPreviewMaxImagesCount
;
/// 【自定义GIF播放方案】为了避免内存过大,内部默认限制只播放50帧(平均取),可通过gifPreviewMaxImagesCount属性调整,若对GIF预览有更好的效果要求,可实现这个block采用FLAnimatedImage等三方库来播放,但注意FLAnimatedImage有播放速度较慢问题,自行取舍下。
@property
(
nonatomic
,
copy
)
void
(
^
gifImagePlayBlock
)(
TZPhotoPreviewView
*
view
,
UIImageView
*
imageView
,
NSData
*
gifData
,
NSDictionary
*
info
);
@end
@end
ios/TZImagePickerController/TZImagePickerController.m
View file @
37b14d5c
This diff is collapsed.
Click to expand it.
ios/TZImagePickerController/TZLocationManager.m
View file @
37b14d5c
...
@@ -28,9 +28,7 @@
...
@@ -28,9 +28,7 @@
manager
=
[[
self
alloc
]
init
];
manager
=
[[
self
alloc
]
init
];
manager
.
locationManager
=
[[
CLLocationManager
alloc
]
init
];
manager
.
locationManager
=
[[
CLLocationManager
alloc
]
init
];
manager
.
locationManager
.
delegate
=
manager
;
manager
.
locationManager
.
delegate
=
manager
;
if
(
iOS8Later
)
{
[
manager
.
locationManager
requestWhenInUseAuthorization
];
[
manager
.
locationManager
requestWhenInUseAuthorization
];
}
});
});
return
manager
;
return
manager
;
}
}
...
...
ios/TZImagePickerController/TZPhotoPickerController.m
View file @
37b14d5c
This diff is collapsed.
Click to expand it.
ios/TZImagePickerController/TZPhotoPreviewCell.m
View file @
37b14d5c
...
@@ -178,7 +178,11 @@
...
@@ -178,7 +178,11 @@
if
(
!
isDegraded
)
{
if
(
!
isDegraded
)
{
self
.
isRequestingGIF
=
NO
;
self
.
isRequestingGIF
=
NO
;
self
.
progressView
.
hidden
=
YES
;
self
.
progressView
.
hidden
=
YES
;
if
([
TZImagePickerConfig
sharedInstance
].
gifImagePlayBlock
)
{
[
TZImagePickerConfig
sharedInstance
].
gifImagePlayBlock
(
self
,
self
.
imageView
,
data
,
info
);
}
else
{
self
.
imageView
.
image
=
[
UIImage
sd_tz_animatedGIFWithData
:
data
];
self
.
imageView
.
image
=
[
UIImage
sd_tz_animatedGIFWithData
:
data
];
}
[
self
resizeSubviews
];
[
self
resizeSubviews
];
}
}
}];
}];
...
@@ -188,7 +192,7 @@
...
@@ -188,7 +192,7 @@
}
}
}
}
-
(
void
)
setAsset
:
(
id
)
asset
{
-
(
void
)
setAsset
:
(
PHAsset
*
)
asset
{
if
(
_asset
&&
self
.
imageRequestID
)
{
if
(
_asset
&&
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
}
}
...
@@ -412,7 +416,7 @@
...
@@ -412,7 +416,7 @@
if
(
currentTime
.
value
==
durationTime
.
value
)
[
_player
.
currentItem
seekToTime
:
CMTimeMake
(
0
,
1
)];
if
(
currentTime
.
value
==
durationTime
.
value
)
[
_player
.
currentItem
seekToTime
:
CMTimeMake
(
0
,
1
)];
[
_player
play
];
[
_player
play
];
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
self
.
singleTapGestureBlock
)
{
if
(
self
.
singleTapGestureBlock
)
{
self
.
singleTapGestureBlock
();
self
.
singleTapGestureBlock
();
}
}
...
...
ios/TZImagePickerController/TZPhotoPreviewController.m
View file @
37b14d5c
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
@property
(
nonatomic
,
strong
)
UIView
*
cropView
;
@property
(
nonatomic
,
strong
)
UIView
*
cropView
;
@property
(
nonatomic
,
assign
)
double
progress
;
@property
(
nonatomic
,
assign
)
double
progress
;
@property
(
strong
,
nonatomic
)
id
alertView
;
@property
(
strong
,
nonatomic
)
UIAlertController
*
alertView
;
@end
@end
@implementation
TZPhotoPreviewController
@implementation
TZPhotoPreviewController
...
@@ -77,8 +77,10 @@
...
@@ -77,8 +77,10 @@
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
animated
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
animated
:
YES
];
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
_currentIndex
)
[
_collectionView
setContentOffset
:
CGPointMake
((
self
.
view
.
tz_width
+
20
)
*
_currentIndex
,
0
)
animated
:
NO
];
if
(
_currentIndex
)
{
[
_collectionView
setContentOffset
:
CGPointMake
((
self
.
view
.
tz_width
+
20
)
*
self
.
currentIndex
,
0
)
animated
:
NO
];
}
[
self
refreshNaviBarAndBottomBarState
];
[
self
refreshNaviBarAndBottomBarState
];
}
}
...
@@ -86,7 +88,7 @@
...
@@ -86,7 +88,7 @@
[
super
viewWillDisappear
:
animated
];
[
super
viewWillDisappear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
animated
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
animated
:
YES
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
needShowStatusBar
&&
iOS7Later
)
{
if
(
tzImagePickerVc
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
[
TZImageManager
manager
].
shouldFixOrientation
=
NO
;
[
TZImageManager
manager
].
shouldFixOrientation
=
NO
;
...
@@ -135,7 +137,7 @@
...
@@ -135,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
,
-
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
];
...
@@ -206,7 +208,7 @@
...
@@ -206,7 +208,7 @@
-
(
void
)
configCropView
{
-
(
void
)
configCropView
{
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
maxImagesCount
<=
1
&&
_tzImagePickerVc
.
allowCrop
)
{
if
(
_tzImagePickerVc
.
maxImagesCount
<=
1
&&
_tzImagePickerVc
.
allowCrop
&&
_tzImagePickerVc
.
allowPickingImage
)
{
[
_cropView
removeFromSuperview
];
[
_cropView
removeFromSuperview
];
[
_cropBgView
removeFromSuperview
];
[
_cropBgView
removeFromSuperview
];
...
@@ -268,7 +270,7 @@
...
@@ -268,7 +270,7 @@
CGFloat
toolBarTop
=
self
.
view
.
tz_height
-
toolBarHeight
;
CGFloat
toolBarTop
=
self
.
view
.
tz_height
-
toolBarHeight
;
_toolBar
.
frame
=
CGRectMake
(
0
,
toolBarTop
,
self
.
view
.
tz_width
,
toolBarHeight
);
_toolBar
.
frame
=
CGRectMake
(
0
,
toolBarTop
,
self
.
view
.
tz_width
,
toolBarHeight
);
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
CGFloat
fullImageWidth
=
[
_tzImagePickerVc
.
fullImageBtnTitleStr
tz_calculateSizeWithAttributes
:@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
maxSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)]
.
width
;
CGFloat
fullImageWidth
=
[
_tzImagePickerVc
.
fullImageBtnTitleStr
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesFontLeading
attributes
:
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
context
:
nil
].
size
.
width
;
_originalPhotoButton
.
frame
=
CGRectMake
(
0
,
0
,
fullImageWidth
+
56
,
44
);
_originalPhotoButton
.
frame
=
CGRectMake
(
0
,
0
,
fullImageWidth
+
56
,
44
);
_originalPhotoLabel
.
frame
=
CGRectMake
(
fullImageWidth
+
42
,
0
,
80
,
44
);
_originalPhotoLabel
.
frame
=
CGRectMake
(
fullImageWidth
+
42
,
0
,
80
,
44
);
}
}
...
@@ -294,7 +296,7 @@
...
@@ -294,7 +296,7 @@
-
(
void
)
select
:
(
UIButton
*
)
selectButton
{
-
(
void
)
select
:
(
UIButton
*
)
selectButton
{
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZAssetModel
*
model
=
_models
[
_
currentIndex
];
TZAssetModel
*
model
=
_models
[
self
.
currentIndex
];
if
(
!
selectButton
.
isSelected
)
{
if
(
!
selectButton
.
isSelected
)
{
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if
(
_tzImagePickerVc
.
selectedModels
.
count
>=
_tzImagePickerVc
.
maxImagesCount
)
{
if
(
_tzImagePickerVc
.
selectedModels
.
count
>=
_tzImagePickerVc
.
maxImagesCount
)
{
...
@@ -305,8 +307,8 @@
...
@@ -305,8 +307,8 @@
}
else
{
}
else
{
[
_tzImagePickerVc
addSelectedModel
:
model
];
[
_tzImagePickerVc
addSelectedModel
:
model
];
if
(
self
.
photos
)
{
if
(
self
.
photos
)
{
[
_tzImagePickerVc
.
selectedAssets
addObject
:
_assetsTemp
[
_
currentIndex
]];
[
_tzImagePickerVc
.
selectedAssets
addObject
:
_assetsTemp
[
self
.
currentIndex
]];
[
self
.
photos
addObject
:
_photosTemp
[
_
currentIndex
]];
[
self
.
photos
addObject
:
_photosTemp
[
self
.
currentIndex
]];
}
}
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
&&
!
_tzImagePickerVc
.
allowPickingMultipleVideo
)
{
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
&&
!
_tzImagePickerVc
.
allowPickingMultipleVideo
)
{
[
_tzImagePickerVc
showAlertWithTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Select the video when in multi state, we will handle the video as a photo"
]];
[
_tzImagePickerVc
showAlertWithTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Select the video when in multi state, we will handle the video as a photo"
]];
...
@@ -315,7 +317,7 @@
...
@@ -315,7 +317,7 @@
}
else
{
}
else
{
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model_item
.
asset
]
])
{
if
([
model
.
asset
.
localIdentifier
isEqualToString
:
model_item
.
asset
.
localIdentifier
])
{
// 1.6.7版本更新:防止有多个一样的model,一次性被移除了
// 1.6.7版本更新:防止有多个一样的model,一次性被移除了
NSArray
*
selectedModelsTmp
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
NSArray
*
selectedModelsTmp
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
for
(
NSInteger
i
=
0
;
i
<
selectedModelsTmp
.
count
;
i
++
)
{
for
(
NSInteger
i
=
0
;
i
<
selectedModelsTmp
.
count
;
i
++
)
{
...
@@ -331,13 +333,13 @@
...
@@ -331,13 +333,13 @@
NSArray
*
selectedAssetsTmp
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
NSArray
*
selectedAssetsTmp
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
for
(
NSInteger
i
=
0
;
i
<
selectedAssetsTmp
.
count
;
i
++
)
{
for
(
NSInteger
i
=
0
;
i
<
selectedAssetsTmp
.
count
;
i
++
)
{
id
asset
=
selectedAssetsTmp
[
i
];
id
asset
=
selectedAssetsTmp
[
i
];
if
([
asset
isEqual
:
_assetsTemp
[
_
currentIndex
]])
{
if
([
asset
isEqual
:
_assetsTemp
[
self
.
currentIndex
]])
{
[
_tzImagePickerVc
.
selectedAssets
removeObjectAtIndex
:
i
];
[
_tzImagePickerVc
.
selectedAssets
removeObjectAtIndex
:
i
];
break
;
break
;
}
}
}
}
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[
_
currentIndex]];
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[
self.
currentIndex]];
[
self
.
photos
removeObject
:
_photosTemp
[
_
currentIndex
]];
[
self
.
photos
removeObject
:
_photosTemp
[
self
.
currentIndex
]];
}
}
break
;
break
;
}
}
...
@@ -378,18 +380,22 @@
...
@@ -378,18 +380,22 @@
// 如果没有选中过照片 点击确定时选中当前预览的照片
// 如果没有选中过照片 点击确定时选中当前预览的照片
if
(
_tzImagePickerVc
.
selectedModels
.
count
==
0
&&
_tzImagePickerVc
.
minImagesCount
<=
0
)
{
if
(
_tzImagePickerVc
.
selectedModels
.
count
==
0
&&
_tzImagePickerVc
.
minImagesCount
<=
0
)
{
TZAssetModel
*
model
=
_models
[
_
currentIndex
];
TZAssetModel
*
model
=
_models
[
self
.
currentIndex
];
[
_tzImagePickerVc
addSelectedModel
:
model
];
[
_tzImagePickerVc
addSelectedModel
:
model
];
}
}
if
(
_tzImagePickerVc
.
allowCrop
)
{
// 裁剪状态
NSIndexPath
*
indexPath
=
[
NSIndexPath
indexPathForItem
:
self
.
currentIndex
inSection
:
0
];
NSIndexPath
*
indexPath
=
[
NSIndexPath
indexPathForItem
:
_currentIndex
inSection
:
0
];
TZPhotoPreviewCell
*
cell
=
(
TZPhotoPreviewCell
*
)[
_collectionView
cellForItemAtIndexPath
:
indexPath
];
TZPhotoPreviewCell
*
cell
=
(
TZPhotoPreviewCell
*
)[
_collectionView
cellForItemAtIndexPath
:
indexPath
];
if
(
_tzImagePickerVc
.
allowCrop
&&
[
cell
isKindOfClass
:[
TZPhotoPreviewCell
class
]])
{
// 裁剪状态
_doneButton
.
enabled
=
NO
;
[
_tzImagePickerVc
showProgressHUD
];
UIImage
*
cropedImage
=
[
TZImageCropManager
cropImageView
:
cell
.
previewView
.
imageView
toRect
:
_tzImagePickerVc
.
cropRect
zoomScale
:
cell
.
previewView
.
scrollView
.
zoomScale
containerView
:
self
.
view
];
UIImage
*
cropedImage
=
[
TZImageCropManager
cropImageView
:
cell
.
previewView
.
imageView
toRect
:
_tzImagePickerVc
.
cropRect
zoomScale
:
cell
.
previewView
.
scrollView
.
zoomScale
containerView
:
self
.
view
];
if
(
_tzImagePickerVc
.
needCircleCrop
)
{
if
(
_tzImagePickerVc
.
needCircleCrop
)
{
cropedImage
=
[
TZImageCropManager
circularClipImage
:
cropedImage
];
cropedImage
=
[
TZImageCropManager
circularClipImage
:
cropedImage
];
}
}
_doneButton
.
enabled
=
YES
;
[
_tzImagePickerVc
hideProgressHUD
];
if
(
self
.
doneButtonClickBlockCropMode
)
{
if
(
self
.
doneButtonClickBlockCropMode
)
{
TZAssetModel
*
model
=
_models
[
_
currentIndex
];
TZAssetModel
*
model
=
_models
[
self
.
currentIndex
];
self
.
doneButtonClickBlockCropMode
(
cropedImage
,
model
.
asset
);
self
.
doneButtonClickBlockCropMode
(
cropedImage
,
model
.
asset
);
}
}
}
else
if
(
self
.
doneButtonClickBlock
)
{
// 非裁剪状态
}
else
if
(
self
.
doneButtonClickBlock
)
{
// 非裁剪状态
...
@@ -429,7 +435,6 @@
...
@@ -429,7 +435,6 @@
offSetWidth
=
offSetWidth
+
((
self
.
view
.
tz_width
+
20
)
*
0
.
5
);
offSetWidth
=
offSetWidth
+
((
self
.
view
.
tz_width
+
20
)
*
0
.
5
);
NSInteger
currentIndex
=
offSetWidth
/
(
self
.
view
.
tz_width
+
20
);
NSInteger
currentIndex
=
offSetWidth
/
(
self
.
view
.
tz_width
+
20
);
if
(
currentIndex
<
_models
.
count
&&
_currentIndex
!=
currentIndex
)
{
if
(
currentIndex
<
_models
.
count
&&
_currentIndex
!=
currentIndex
)
{
_currentIndex
=
currentIndex
;
_currentIndex
=
currentIndex
;
[
self
refreshNaviBarAndBottomBarState
];
[
self
refreshNaviBarAndBottomBarState
];
...
@@ -509,12 +514,11 @@
...
@@ -509,12 +514,11 @@
-
(
void
)
refreshNaviBarAndBottomBarState
{
-
(
void
)
refreshNaviBarAndBottomBarState
{
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZAssetModel
*
model
=
_models
[
_
currentIndex
];
TZAssetModel
*
model
=
_models
[
self
.
currentIndex
];
_selectButton
.
selected
=
model
.
isSelected
;
_selectButton
.
selected
=
model
.
isSelected
;
[
self
refreshSelectButtonImageViewContentMode
];
[
self
refreshSelectButtonImageViewContentMode
];
if
(
_selectButton
.
isSelected
&&
_tzImagePickerVc
.
showSelectedIndex
&&
_tzImagePickerVc
.
showSelectBtn
)
{
if
(
_selectButton
.
isSelected
&&
_tzImagePickerVc
.
showSelectedIndex
&&
_tzImagePickerVc
.
showSelectBtn
)
{
NSString
*
assetId
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
NSString
*
index
=
[
NSString
stringWithFormat
:
@"%d"
,
(
int
)([
_tzImagePickerVc
.
selectedAssetIds
indexOfObject
:
model
.
asset
.
localIdentifier
]
+
1
)];
NSString
*
index
=
[
NSString
stringWithFormat
:
@"%zd"
,
[
_tzImagePickerVc
.
selectedAssetIds
indexOfObject
:
assetId
]
+
1
];
_indexLabel
.
text
=
index
;
_indexLabel
.
text
=
index
;
_indexLabel
.
hidden
=
NO
;
_indexLabel
.
hidden
=
NO
;
}
else
{
}
else
{
...
@@ -564,9 +568,13 @@
...
@@ -564,9 +568,13 @@
}
}
-
(
void
)
showPhotoBytes
{
-
(
void
)
showPhotoBytes
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:@[
_models
[
_
currentIndex
]]
completion
:
^
(
NSString
*
totalBytes
)
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:@[
_models
[
self
.
currentIndex
]]
completion
:
^
(
NSString
*
totalBytes
)
{
self
->
_originalPhotoLabel
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
self
->
_originalPhotoLabel
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
}];
}];
}
}
-
(
NSInteger
)
currentIndex
{
return
[
TZCommonTools
isRightToLeftLayout
]
?
self
.
models
.
count
-
_currentIndex
-
1
:
_currentIndex
;
}
@end
@end
ios/TZImagePickerController/TZVideoPlayerController.m
View file @
37b14d5c
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
_originStatusBarStyle
=
[
UIApplication
sharedApplication
].
statusBarStyle
;
_originStatusBarStyle
=
[
UIApplication
sharedApplication
].
statusBarStyle
;
[
UIApplication
sharedApplication
].
statusBarStyle
=
iOS7Later
?
UIStatusBarStyleLightContent
:
UIStatusBarStyleBlackOpaque
;
[
UIApplication
sharedApplication
].
statusBarStyle
=
UIStatusBarStyleLightContent
;
}
}
-
(
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
-
(
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
...
@@ -127,6 +127,14 @@
...
@@ -127,6 +127,14 @@
}
}
}
}
-
(
UIStatusBarStyle
)
preferredStatusBarStyle
{
TZImagePickerController
*
tzImagePicker
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePicker
&&
[
tzImagePicker
isKindOfClass
:[
TZImagePickerController
class
]])
{
return
tzImagePicker
.
statusBarStyle
;
}
return
[
super
preferredStatusBarStyle
];
}
#pragma mark - Layout
#pragma mark - Layout
-
(
void
)
viewDidLayoutSubviews
{
-
(
void
)
viewDidLayoutSubviews
{
...
@@ -157,7 +165,7 @@
...
@@ -157,7 +165,7 @@
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
_toolBar
.
hidden
=
YES
;
_toolBar
.
hidden
=
YES
;
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
else
{
}
else
{
[
self
pausePlayerAndShowNaviBar
];
[
self
pausePlayerAndShowNaviBar
];
}
}
...
@@ -198,7 +206,7 @@
...
@@ -198,7 +206,7 @@
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
self
.
needShowStatusBar
&&
iOS7Later
)
{
if
(
self
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
}
}
...
...
package.json
View file @
37b14d5c
{
{
"name"
:
"react-native-syan-image-picker"
,
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.1.
7
"
,
"version"
:
"0.1.
8
"
,
"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