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
8c366ca4
Commit
8c366ca4
authored
Jan 18, 2018
by
少言
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.0.9--新增打开相机
parent
c599b972
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
599 additions
and
213 deletions
+599
-213
README.md
README.md
+17
-3
RNSyanImagePickerModule.java
...c/main/java/com/reactlibrary/RNSyanImagePickerModule.java
+78
-33
index.js
index.js
+15
-1
RNSyanImagePicker.h
ios/RNSyanImagePicker.h
+3
-3
RNSyanImagePicker.m
ios/RNSyanImagePicker.m
+187
-36
project.pbxproj
ios/RNSyanImagePicker.xcodeproj/project.pbxproj
+8
-2
NSBundle+TZImagePicker.m
ios/TZImagePickerController/NSBundle+TZImagePicker.m
+2
-0
TZGifPhotoPreviewController.m
ios/TZImagePickerController/TZGifPhotoPreviewController.m
+11
-5
TZImageManager.h
ios/TZImagePickerController/TZImageManager.h
+6
-3
TZImageManager.m
ios/TZImagePickerController/TZImageManager.m
+91
-37
TZImagePickerController.h
ios/TZImagePickerController/TZImagePickerController.h
+10
-4
TZImagePickerController.m
ios/TZImagePickerController/TZImagePickerController.m
+76
-21
TZPhotoPickerController.m
ios/TZImagePickerController/TZPhotoPickerController.m
+39
-28
TZPhotoPreviewCell.h
ios/TZImagePickerController/TZPhotoPreviewCell.h
+2
-2
TZPhotoPreviewCell.m
ios/TZImagePickerController/TZPhotoPreviewCell.m
+9
-8
TZPhotoPreviewController.m
ios/TZImagePickerController/TZPhotoPreviewController.m
+30
-19
TZVideoPlayerController.m
ios/TZImagePickerController/TZVideoPlayerController.m
+14
-7
package.json
package.json
+1
-1
No files found.
README.md
View file @
8c366ca4
...
...
@@ -7,7 +7,7 @@
Android 基于
[
PictureSelector 2.0
](
https://github.com/LuckSiege/PictureSelector
)
iOS 基于
[
TZImagePickerController 1.9.
0
](
https://github.com/banchichen/TZImagePickerController
)
iOS 基于
[
TZImagePickerController 1.9.
5
](
https://github.com/banchichen/TZImagePickerController
)


...
...
@@ -115,7 +115,8 @@ import SYImagePicker from 'react-native-syan-image-picker'
showCropCircle: false, // 是否显示圆形裁剪区域,默认false
circleCropRadius: width/2 // 圆形裁剪半径,默认屏幕宽度一半
showCropFrame: true, // 是否显示裁剪区域,默认true
showCropGrid: false // 是否隐藏裁剪区域网格,默认false
showCropGrid: false, // 是否隐藏裁剪区域网格,默认false
quality: 90 // 压缩质量
};
/
**
...
...
@@ -125,7 +126,7 @@ import SYImagePicker from 'react-native-syan-image-picker'
*
1)选择图片成功,err为null,selectedPhotos为选中的图片数组
*
2)取消时,err返回"取消",selectedPhotos将为undefined
*
按需判断各参数值,确保调用正常,示例使用方式:
*
showImagePicker(options, (err, selectedPhotos) => {
*
SYImagePicker.
showImagePicker(options, (err, selectedPhotos) => {
*
if (err) {
*
// 取消选择
*
return;
...
...
@@ -163,6 +164,19 @@ import SYImagePicker from 'react-native-syan-image-picker'
* @param {Object} options 相册参数
* @return {Promise} 返回一个Promise对象
*/
/**
* 打开相机
* @param options
* @param callback
*/
* SYImagePicker.openCamera(options, (err, selectedPhotos) => {
* if (err) {
* // 取消选择
* return;
* }
* // 选择成功
* })
```
## 帮助
...
...
android/src/main/java/com/reactlibrary/RNSyanImagePickerModule.java
View file @
8c366ca4
...
...
@@ -63,6 +63,14 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
this
.
openImagePicker
(
options
);
}
@ReactMethod
public
void
openCamera
(
ReadableMap
options
,
Callback
callback
)
{
this
.
mPickerPromise
=
null
;
this
.
mPickerCallback
=
callback
;
this
.
openCamera
(
options
);
}
/**
* 打开相册选择
*
...
...
@@ -78,6 +86,7 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
boolean
showCropCircle
=
options
.
getBoolean
(
"showCropCircle"
);
boolean
showCropFrame
=
options
.
getBoolean
(
"showCropFrame"
);
boolean
showCropGrid
=
options
.
getBoolean
(
"showCropGrid"
);
int
quality
=
options
.
getInt
(
"quality"
);
int
modeValue
;
if
(
imageCount
==
1
)
{
...
...
@@ -87,39 +96,75 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
}
Activity
currentActivity
=
getCurrentActivity
();
PictureSelector
.
create
(
currentActivity
)
.
openGallery
(
PictureMimeType
.
ofImage
())
//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
.
maxSelectNum
(
imageCount
)
// 最大图片选择数量 int
.
minSelectNum
(
1
)
// 最小选择数量 int
.
imageSpanCount
(
4
)
// 每行显示个数 int
.
selectionMode
(
modeValue
)
// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
.
previewImage
(
true
)
// 是否可预览图片 true or false
.
previewVideo
(
false
)
// 是否可预览视频 true or false
.
enablePreviewAudio
(
false
)
// 是否可播放音频 true or false
.
isCamera
(
isCamera
)
// 是否显示拍照按钮 true or false
.
imageFormat
(
PictureMimeType
.
PNG
)
// 拍照保存图片格式后缀,默认jpeg
.
isZoomAnim
(
true
)
// 图片列表点击 缩放效果 默认true
.
sizeMultiplier
(
0.5f
)
// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
.
enableCrop
(
isCrop
)
// 是否裁剪 true or false
.
compress
(
true
)
// 是否压缩 true or false
.
glideOverride
(
160
,
160
)
// int glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
.
withAspectRatio
(
CropW
,
CropH
)
// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
.
hideBottomControls
(
isCrop
)
// 是否显示uCrop工具栏,默认不显示 true or false
.
isGif
(
isGif
)
// 是否显示gif图片 true or false
.
freeStyleCropEnabled
(
true
)
// 裁剪框是否可拖拽 true or false
.
circleDimmedLayer
(
showCropCircle
)
// 是否圆形裁剪 true or false
.
showCropFrame
(
showCropFrame
)
// 是否显示裁剪矩形边框 圆形裁剪时建议设为false true or false
.
showCropGrid
(
showCropGrid
)
// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
.
openClickSound
(
false
)
// 是否开启点击声音 true or false
.
cropCompressQuality
(
90
)
// 裁剪压缩质量 默认90 int
.
minimumCompressSize
(
100
)
// 小于100kb的图片不压缩
.
synOrAsy
(
true
)
//同步true或异步false 压缩 默认同步
.
rotateEnabled
(
true
)
// 裁剪是否可旋转图片 true or false
.
scaleEnabled
(
true
)
// 裁剪是否可放大缩小图片 true or false
.
videoQuality
(
0
)
// 视频录制质量 0 or 1 int
.
videoMaxSecond
(
15
)
// 显示多少秒以内的视频or音频也可适用 int
.
videoMinSecond
(
10
)
// 显示多少秒以内的视频or音频也可适用 int
.
recordVideoSecond
(
60
)
//视频秒数录制 默认60s int
.
forResult
(
PictureConfig
.
CHOOSE_REQUEST
);
//结果回调onActivityResult code
.
openGallery
(
PictureMimeType
.
ofImage
())
//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
.
maxSelectNum
(
imageCount
)
// 最大图片选择数量 int
.
minSelectNum
(
1
)
// 最小选择数量 int
.
imageSpanCount
(
4
)
// 每行显示个数 int
.
selectionMode
(
modeValue
)
// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
.
previewImage
(
true
)
// 是否可预览图片 true or false
.
previewVideo
(
false
)
// 是否可预览视频 true or false
.
enablePreviewAudio
(
false
)
// 是否可播放音频 true or false
.
isCamera
(
isCamera
)
// 是否显示拍照按钮 true or false
.
imageFormat
(
PictureMimeType
.
PNG
)
// 拍照保存图片格式后缀,默认jpeg
.
isZoomAnim
(
true
)
// 图片列表点击 缩放效果 默认true
.
sizeMultiplier
(
0.5f
)
// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
.
enableCrop
(
isCrop
)
// 是否裁剪 true or false
.
compress
(
true
)
// 是否压缩 true or false
.
glideOverride
(
160
,
160
)
// int glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
.
withAspectRatio
(
CropW
,
CropH
)
// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
.
hideBottomControls
(
isCrop
)
// 是否显示uCrop工具栏,默认不显示 true or false
.
isGif
(
isGif
)
// 是否显示gif图片 true or false
.
freeStyleCropEnabled
(
true
)
// 裁剪框是否可拖拽 true or false
.
circleDimmedLayer
(
showCropCircle
)
// 是否圆形裁剪 true or false
.
showCropFrame
(
showCropFrame
)
// 是否显示裁剪矩形边框 圆形裁剪时建议设为false true or false
.
showCropGrid
(
showCropGrid
)
// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
.
openClickSound
(
false
)
// 是否开启点击声音 true or false
.
cropCompressQuality
(
quality
)
// 裁剪压缩质量 默认90 int
.
minimumCompressSize
(
100
)
// 小于100kb的图片不压缩
.
synOrAsy
(
true
)
//同步true或异步false 压缩 默认同步
.
rotateEnabled
(
true
)
// 裁剪是否可旋转图片 true or false
.
scaleEnabled
(
true
)
// 裁剪是否可放大缩小图片 true or false
//.videoQuality(0)// 视频录制质量 0 or 1 int
//.videoMaxSecond(15)// 显示多少秒以内的视频or音频也可适用 int
//.videoMinSecond(10)// 显示多少秒以内的视频or音频也可适用 int
//.recordVideoSecond(60)//视频秒数录制 默认60s int
.
forResult
(
PictureConfig
.
CHOOSE_REQUEST
);
//结果回调onActivityResult code
}
/**
* 打开相册选择
*
* @param options 相册参数
*/
private
void
openCamera
(
ReadableMap
options
)
{
boolean
isCrop
=
options
.
getBoolean
(
"isCrop"
);
int
CropW
=
options
.
getInt
(
"CropW"
);
int
CropH
=
options
.
getInt
(
"CropH"
);
boolean
showCropCircle
=
options
.
getBoolean
(
"showCropCircle"
);
boolean
showCropFrame
=
options
.
getBoolean
(
"showCropFrame"
);
boolean
showCropGrid
=
options
.
getBoolean
(
"showCropGrid"
);
int
quality
=
options
.
getInt
(
"quality"
);
Activity
currentActivity
=
getCurrentActivity
();
PictureSelector
.
create
(
currentActivity
)
.
openCamera
(
PictureMimeType
.
ofImage
())
.
imageFormat
(
PictureMimeType
.
PNG
)
// 拍照保存图片格式后缀,默认jpeg
.
enableCrop
(
isCrop
)
// 是否裁剪 true or false
.
compress
(
true
)
// 是否压缩 true or false
.
glideOverride
(
160
,
160
)
// int glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
.
withAspectRatio
(
CropW
,
CropH
)
// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
.
hideBottomControls
(
isCrop
)
// 是否显示uCrop工具栏,默认不显示 true or false
.
freeStyleCropEnabled
(
true
)
// 裁剪框是否可拖拽 true or false
.
circleDimmedLayer
(
showCropCircle
)
// 是否圆形裁剪 true or false
.
showCropFrame
(
showCropFrame
)
// 是否显示裁剪矩形边框 圆形裁剪时建议设为false true or false
.
showCropGrid
(
showCropGrid
)
// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
.
openClickSound
(
false
)
// 是否开启点击声音 true or false
.
cropCompressQuality
(
quality
)
// 裁剪压缩质量 默认90 int
.
minimumCompressSize
(
100
)
// 小于100kb的图片不压缩
.
synOrAsy
(
true
)
//同步true或异步false 压缩 默认同步
.
rotateEnabled
(
true
)
// 裁剪是否可旋转图片 true or false
.
scaleEnabled
(
true
)
// 裁剪是否可放大缩小图片 true or false
.
forResult
(
PictureConfig
.
CHOOSE_REQUEST
);
//结果回调onActivityResult code
}
private
final
ActivityEventListener
mActivityEventListener
=
new
BaseActivityEventListener
()
{
...
...
index.js
View file @
8c366ca4
...
...
@@ -19,7 +19,8 @@ const defaultOptions = {
showCropCircle
:
false
,
// 是否显示圆形裁剪区域,默认false
circleCropRadius
:
width
/
2
,
// 圆形裁剪半径,默认屏幕宽度一半
showCropFrame
:
true
,
// 是否显示裁剪区域,默认true
showCropGrid
:
false
// 是否隐藏裁剪区域网格,默认false
showCropGrid
:
false
,
// 是否隐藏裁剪区域网格,默认false
quality
:
90
// 压缩质量
};
export
default
{
...
...
@@ -81,5 +82,18 @@ export default {
...
options
,
};
return
RNSyanImagePicker
.
asyncShowImagePicker
(
optionObj
);
},
/**
* 打开相机支持裁剪参数
* @param options
* @param callback
*/
openCamera
(
options
,
callback
)
{
const
optionObj
=
{
...
defaultOptions
,
...
options
};
RNSyanImagePicker
.
openCamera
(
optionObj
,
callback
)
}
};
ios/RNSyanImagePicker.h
View file @
8c366ca4
...
...
@@ -4,8 +4,8 @@
#else
#import <React/RCTBridgeModule.h>
#endif
@interface
RNSyanImagePicker
:
NSObject
<
RCTBridgeModule
>
#import <UIKit/UIKit.h>
@interface
RNSyanImagePicker
:
NSObject
<
RCTBridgeModule
,
UINavigationControllerDelegate
,
UIImagePickerControllerDelegate
,
UIActionSheetDelegate
>
@end
\ No newline at end of file
ios/RNSyanImagePicker.m
View file @
8c366ca4
This diff is collapsed.
Click to expand it.
ios/RNSyanImagePicker.xcodeproj/project.pbxproj
View file @
8c366ca4
...
...
@@ -296,7 +296,10 @@
58B511F01A9E6C8500147676
/* Debug */
=
{
isa
=
XCBuildConfiguration
;
buildSettings
=
{
HEADER_SEARCH_PATHS
=
"$(inherited)"
;
HEADER_SEARCH_PATHS
=
(
"$(inherited)"
,
"\"$(SRCROOT)/../../react-native/React\""
,
);
LIBRARY_SEARCH_PATHS
=
"$(inherited)"
;
OTHER_LDFLAGS
=
"-ObjC"
;
PRODUCT_NAME
=
RNSyanImagePicker
;
...
...
@@ -307,7 +310,10 @@
58B511F11A9E6C8500147676
/* Release */
=
{
isa
=
XCBuildConfiguration
;
buildSettings
=
{
HEADER_SEARCH_PATHS
=
"$(inherited)"
;
HEADER_SEARCH_PATHS
=
(
"$(inherited)"
,
"\"$(SRCROOT)/../../react-native/React\""
,
);
LIBRARY_SEARCH_PATHS
=
"$(inherited)"
;
OTHER_LDFLAGS
=
"-ObjC"
;
PRODUCT_NAME
=
RNSyanImagePicker
;
...
...
ios/TZImagePickerController/NSBundle+TZImagePicker.m
View file @
8c366ca4
...
...
@@ -28,6 +28,8 @@
NSString
*
language
=
[
NSLocale
preferredLanguages
].
firstObject
;
if
([
language
rangeOfString
:
@"zh-Hans"
].
location
!=
NSNotFound
)
{
language
=
@"zh-Hans"
;
}
else
if
([
language
rangeOfString
:
@"zh-Hant"
].
location
!=
NSNotFound
)
{
language
=
@"zh-Hant"
;
}
else
{
language
=
@"en"
;
}
...
...
ios/TZImagePickerController/TZGifPhotoPreviewController.m
View file @
8c366ca4
...
...
@@ -56,7 +56,8 @@
_previewView
.
model
=
self
.
model
;
__weak
typeof
(
self
)
weakSelf
=
self
;
[
_previewView
setSingleTapGestureBlock
:
^
{
[
weakSelf
signleTapAction
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
signleTapAction
];
}];
[
self
.
view
addSubview
:
_previewView
];
}
...
...
@@ -98,8 +99,9 @@
_previewView
.
frame
=
self
.
view
.
bounds
;
_previewView
.
scrollView
.
frame
=
self
.
view
.
bounds
;
CGFloat
toolBarHeight
=
[
TZCommonTools
tz_isIPhoneX
]
?
44
+
(
83
-
49
)
:
44
;
_toolBar
.
frame
=
CGRectMake
(
0
,
self
.
view
.
tz_height
-
toolBarHeight
,
self
.
view
.
tz_width
,
toolBarHeight
);
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
44
-
12
,
0
,
44
,
44
);
_toolBar
.
frame
=
CGRectMake
(
0
,
self
.
view
.
tz_height
-
44
,
self
.
view
.
tz_width
,
44
);
}
#pragma mark - Click Event
...
...
@@ -107,9 +109,13 @@
-
(
void
)
signleTapAction
{
_toolBar
.
hidden
=
!
_toolBar
.
isHidden
;
[
self
.
navigationController
setNavigationBarHidden
:
_toolBar
.
isHidden
];
if
(
!
TZ_isGlobalHideStatusBar
)
{
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
_toolBar
.
isHidden
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
iOS7Later
)
{
if
(
_toolBar
.
isHidden
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
else
if
(
tzImagePickerVc
.
needShowStatusBar
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
}
...
...
ios/TZImagePickerController/TZImageManager.h
View file @
8c366ca4
...
...
@@ -47,7 +47,7 @@
/// Return YES if Authorized 返回YES如果得到了授权
-
(
BOOL
)
authorizationStatusAuthorized
;
+
(
NSInteger
)
authorizationStatus
;
-
(
void
)
requestAuthorizationWithCompletion
:(
void
(
^
)())
completion
;
-
(
void
)
requestAuthorizationWithCompletion
:(
void
(
^
)(
void
))
completion
;
/// Get Album 获得相册/相册数组
-
(
void
)
getCameraRollAlbum
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAlbumModel
*
model
))
completion
;
...
...
@@ -80,8 +80,11 @@
-
(
void
)
getVideoWithAsset
:(
id
)
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
;
/// Export video 导出视频
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
;
/// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
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
;
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
__attribute__
((
deprecated
(
"Use -getVideoOutputPathWithAsset:failure:success:"
)));
/// Get photo bytes 获得一组照片的大小
-
(
void
)
getPhotosBytesWithArray
:(
NSArray
*
)
photos
completion
:(
void
(
^
)(
NSString
*
totalBytes
))
completion
;
...
...
ios/TZImagePickerController/TZImageManager.m
View file @
8c366ca4
This diff is collapsed.
Click to expand it.
ios/TZImagePickerController/TZImagePickerController.h
View file @
8c366ca4
...
...
@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.9.
3 - 2017.09.13
// version 1.9.
8 - 2017.12.19
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
/*
...
...
@@ -25,8 +25,6 @@
#define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
#define iOS9_1Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.1f)
#define TZ_isGlobalHideStatusBar [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue]
@protocol
TZImagePickerControllerDelegate
;
@interface
TZImagePickerController
:
UINavigationController
...
...
@@ -126,6 +124,7 @@
-
(
void
)
showProgressHUD
;
-
(
void
)
hideProgressHUD
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
@property
(
assign
,
nonatomic
)
BOOL
needShowStatusBar
;
@property
(
nonatomic
,
copy
)
NSString
*
takePictureImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoSelImageName
;
...
...
@@ -166,7 +165,7 @@
// 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
)();
@property
(
nonatomic
,
copy
)
void
(
^
imagePickerControllerDidCancelHandle
)(
void
);
// If user picking a video, this handle will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
...
...
@@ -233,5 +232,12 @@
@interface
NSString
(
TzExtension
)
-
(
BOOL
)
tz_containsString
:(
NSString
*
)
string
;
-
(
CGSize
)
tz_calculateSizeWithAttributes
:(
NSDictionary
*
)
attributes
maxSize
:(
CGSize
)
maxSize
;
@end
@interface
TZCommonTools
:
NSObject
+
(
BOOL
)
tz_isIPhoneX
;
+
(
CGFloat
)
tz_statusBarHeight
;
@end
ios/TZImagePickerController/TZImagePickerController.m
View file @
8c366ca4
...
...
@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.9.
3 - 2017.09.13
// version 1.9.
8 - 2017.12.19
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
#import "TZImagePickerController.h"
...
...
@@ -14,6 +14,7 @@
#import "TZAssetCell.h"
#import "UIView+Layout.h"
#import "TZImageManager.h"
#import <sys/utsname.h>
@interface
TZImagePickerController
()
{
NSTimer
*
_timer
;
...
...
@@ -36,10 +37,19 @@
@implementation
TZImagePickerController
-
(
instancetype
)
init
{
self
=
[
super
init
];
if
(
self
)
{
self
=
[
self
initWithMaxImagesCount
:
9
delegate
:
nil
];
}
return
self
;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self
.
needShowStatusBar
=
!
[
UIApplication
sharedApplication
].
statusBarHidden
;
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
navigationBar
.
barStyle
=
UIBarStyleBlack
;
self
.
navigationBar
.
translucent
=
YES
;
...
...
@@ -54,13 +64,15 @@
self
.
navigationBar
.
barTintColor
=
[
UIColor
colorWithRed
:(
34
/
255
.
0
)
green
:(
34
/
255
.
0
)
blue
:
(
34
/
255
.
0
)
alpha
:
1
.
0
];
self
.
navigationBar
.
tintColor
=
[
UIColor
whiteColor
];
self
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
!
TZ_isGlobalHide
StatusBar
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
if
(
self
.
needShow
StatusBar
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
-
(
void
)
setNaviBgColor
:
(
UIColor
*
)
naviBgColor
{
_naviBgColor
=
naviBgColor
;
self
.
navigationBar
.
barTintColor
=
naviBgColor
;
if
(
iOS7Later
)
{
self
.
navigationBar
.
barTintColor
=
naviBgColor
;
}
}
-
(
void
)
setNaviTitleColor
:
(
UIColor
*
)
naviTitleColor
{
...
...
@@ -75,8 +87,12 @@
-
(
void
)
configNaviTitleAppearance
{
NSMutableDictionary
*
textAttrs
=
[
NSMutableDictionary
dictionary
];
textAttrs
[
NSForegroundColorAttributeName
]
=
self
.
naviTitleColor
;
textAttrs
[
NSFontAttributeName
]
=
self
.
naviTitleFont
;
if
(
self
.
naviTitleColor
)
{
textAttrs
[
NSForegroundColorAttributeName
]
=
self
.
naviTitleColor
;
}
if
(
self
.
naviTitleFont
)
{
textAttrs
[
NSFontAttributeName
]
=
self
.
naviTitleFont
;
}
self
.
navigationBar
.
titleTextAttributes
=
textAttrs
;
}
...
...
@@ -92,7 +108,7 @@
-
(
void
)
configBarButtonItemAppearance
{
UIBarButtonItem
*
barItem
;
if
(
iOS9Later
)
{
if
(
@available
(
iOS
9
.
0
,
*
)
)
{
barItem
=
[
UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses
:@[[
TZImagePickerController
class
]]];
}
else
{
barItem
=
[
UIBarButtonItem
appearanceWhenContainedIn
:[
TZImagePickerController
class
],
nil
];
...
...
@@ -109,7 +125,7 @@
if
(
self
.
isStatusBarDefault
)
{
[
UIApplication
sharedApplication
].
statusBarStyle
=
iOS7Later
?
UIStatusBarStyleDefault
:
UIStatusBarStyleBlackOpaque
;
}
else
{
}
else
{
[
UIApplication
sharedApplication
].
statusBarStyle
=
iOS7Later
?
UIStatusBarStyleLightContent
:
UIStatusBarStyleBlackOpaque
;
}
}
...
...
@@ -157,7 +173,7 @@
_tipLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_tipLabel
.
textColor
=
[
UIColor
blackColor
];
NSDictionary
*
infoDict
=
[
NSBundle
mainBundle
].
localizedInfoDictionary
;
if
(
!
infoDict
)
{
if
(
!
infoDict
||
!
infoDict
.
count
)
{
infoDict
=
[
NSBundle
mainBundle
].
infoDictionary
;
}
NSString
*
appName
=
[
infoDict
valueForKey
:
@"CFBundleDisplayName"
];
...
...
@@ -196,9 +212,11 @@
previewVc
.
currentIndex
=
index
;
__weak
typeof
(
self
)
weakSelf
=
self
;
[
previewVc
setDoneButtonClickBlockWithPreviewType
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
[
weakSelf
dismissViewControllerAnimated
:
YES
completion
:
^
{
if
(
weakSelf
.
didFinishPickingPhotosHandle
)
{
weakSelf
.
didFinishPickingPhotosHandle
(
photos
,
assets
,
isSelectOriginalPhoto
);
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
dismissViewControllerAnimated
:
YES
completion
:
^
{
if
(
!
strongSelf
)
return
;
if
(
strongSelf
.
didFinishPickingPhotosHandle
)
{
strongSelf
.
didFinishPickingPhotosHandle
(
photos
,
assets
,
isSelectOriginalPhoto
);
}
}];
}];
...
...
@@ -221,7 +239,8 @@
previewVc
.
currentIndex
=
0
;
__weak
typeof
(
self
)
weakSelf
=
self
;
[
previewVc
setDoneButtonClickBlockCropMode
:
^
(
UIImage
*
cropImage
,
id
asset
)
{
[
weakSelf
dismissViewControllerAnimated
:
YES
completion
:
^
{
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
dismissViewControllerAnimated
:
YES
completion
:
^
{
if
(
completion
)
{
completion
(
cropImage
,
asset
);
}
...
...
@@ -350,7 +369,8 @@
// if over time, dismiss HUD automatic
__weak
typeof
(
self
)
weakSelf
=
self
;
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
self
.
timeout
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
[
weakSelf
hideProgressHUD
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
hideProgressHUD
];
});
}
...
...
@@ -520,7 +540,7 @@
-
(
void
)
willInterfaceOrientionChange
{
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
02
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
if
(
!
[
UIApplication
sharedApplication
].
statusBarHidden
)
{
if
(
iOS7Later
&&
!
TZ_isGlobalHide
StatusBar
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
if
(
iOS7Later
&&
self
.
needShow
StatusBar
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
});
}
...
...
@@ -599,12 +619,11 @@
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[[
TZImageManager
manager
]
getAllAlbums
:
imagePickerVc
.
allowPickingVideo
allowPickingImage
:
imagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAlbumModel
*>
*
models
)
{
_albumArr
=
[
NSMutableArray
arrayWithArray
:
models
];
for
(
TZAlbumModel
*
albumModel
in
_albumArr
)
{
albumModel
.
selectedModels
=
imagePickerVc
.
selectedModels
;
}
dispatch_async
(
dispatch_get_main_queue
(),
^
{
_albumArr
=
[
NSMutableArray
arrayWithArray
:
models
];
for
(
TZAlbumModel
*
albumModel
in
_albumArr
)
{
albumModel
.
selectedModels
=
imagePickerVc
.
selectedModels
;
}
if
(
!
_tableView
)
{
_tableView
=
[[
UITableView
alloc
]
initWithFrame
:
CGRectZero
style
:
UITableViewStylePlain
];
_tableView
.
rowHeight
=
70
;
...
...
@@ -636,7 +655,7 @@
BOOL
isStatusBarHidden
=
[
UIApplication
sharedApplication
].
isStatusBarHidden
;
if
(
self
.
navigationController
.
navigationBar
.
isTranslucent
)
{
top
=
naviBarHeight
;
if
(
iOS7Later
&&
!
isStatusBarHidden
)
top
+=
20
;
if
(
iOS7Later
&&
!
isStatusBarHidden
)
top
+=
[
TZCommonTools
tz_statusBarHeight
]
;
tableViewHeight
=
self
.
view
.
tz_height
-
top
;
}
else
{
tableViewHeight
=
self
.
view
.
tz_height
;
...
...
@@ -702,4 +721,40 @@
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-
(
CGSize
)
tz_calculateSizeWithAttributes
:(
NSDictionary
*
)
attributes
maxSize
:(
CGSize
)
maxSize
{
CGSize
size
;
if
(
iOS7Later
)
{
size
=
[
self
boundingRectWithSize
:
maxSize
options
:
NSStringDrawingUsesFontLeading
attributes
:
attributes
context
:
nil
].
size
;
}
else
{
size
=
[
self
sizeWithFont
:
attributes
[
NSFontAttributeName
]
constrainedToSize
:
maxSize
];
}
return
size
;
}
#pragma clang diagnostic pop
@end
@implementation
TZCommonTools
+
(
BOOL
)
tz_isIPhoneX
{
struct
utsname
systemInfo
;
uname
(
&
systemInfo
);
NSString
*
platform
=
[
NSString
stringWithCString
:
systemInfo
.
machine
encoding
:
NSASCIIStringEncoding
];
if
([
platform
isEqualToString
:
@"i386"
]
||
[
platform
isEqualToString
:
@"x86_64"
])
{
// 模拟器下采用屏幕的高度来判断
return
(
CGSizeEqualToSize
([
UIScreen
mainScreen
].
bounds
.
size
,
CGSizeMake
(
375
,
812
))
||
CGSizeEqualToSize
([
UIScreen
mainScreen
].
bounds
.
size
,
CGSizeMake
(
812
,
375
)));
}
// iPhone10,6是美版iPhoneX 感谢hegelsu指出:https://github.com/banchichen/TZImagePickerController/issues/635
BOOL
isIPhoneX
=
[
platform
isEqualToString
:
@"iPhone10,3"
]
||
[
platform
isEqualToString
:
@"iPhone10,6"
];
return
isIPhoneX
;
}
+
(
CGFloat
)
tz_statusBarHeight
{
return
[
self
tz_isIPhoneX
]
?
44
:
20
;
}
@end
ios/TZImagePickerController/TZPhotoPickerController.m
View file @
8c366ca4
...
...
@@ -54,10 +54,12 @@ static CGFloat itemMargin = 5;
_imagePickerVc
=
[[
UIImagePickerController
alloc
]
init
];
_imagePickerVc
.
delegate
=
self
;
// set appearance / 改变相册选择页的导航栏外观
_imagePickerVc
.
navigationBar
.
barTintColor
=
self
.
navigationController
.
navigationBar
.
barTintColor
;
if
(
iOS7Later
)
{
_imagePickerVc
.
navigationBar
.
barTintColor
=
self
.
navigationController
.
navigationBar
.
barTintColor
;
}
_imagePickerVc
.
navigationBar
.
tintColor
=
self
.
navigationController
.
navigationBar
.
tintColor
;
UIBarButtonItem
*
tzBarItem
,
*
BarItem
;
if
(
iOS9Later
)
{
if
(
@available
(
iOS
9
.
0
,
*
)
)
{
tzBarItem
=
[
UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses
:@[[
TZImagePickerController
class
]]];
BarItem
=
[
UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses
:@[[
UIImagePickerController
class
]]];
}
else
{
...
...
@@ -250,8 +252,8 @@ static CGFloat itemMargin = 5;
[
_bottomToolBar
addSubview
:
_doneButton
];
[
_bottomToolBar
addSubview
:
_numberImageView
];
[
_bottomToolBar
addSubview
:
_numberLabel
];
[
_bottomToolBar
addSubview
:
_originalPhotoButton
];
[
self
.
view
addSubview
:
_bottomToolBar
];
[
self
.
view
addSubview
:
_originalPhotoButton
];
[
_originalPhotoButton
addSubview
:
_originalPhotoLabel
];
}
...
...
@@ -266,12 +268,13 @@ static CGFloat itemMargin = 5;
CGFloat
collectionViewHeight
=
0
;
CGFloat
naviBarHeight
=
self
.
navigationController
.
navigationBar
.
tz_height
;
BOOL
isStatusBarHidden
=
[
UIApplication
sharedApplication
].
isStatusBarHidden
;
CGFloat
toolBarHeight
=
[
TZCommonTools
tz_isIPhoneX
]
?
50
+
(
83
-
49
)
:
50
;
if
(
self
.
navigationController
.
navigationBar
.
isTranslucent
)
{
top
=
naviBarHeight
;
if
(
iOS7Later
&&
!
isStatusBarHidden
)
top
+=
20
;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
50
-
top
:
self
.
view
.
tz_height
-
top
;;
if
(
iOS7Later
&&
!
isStatusBarHidden
)
top
+=
[
TZCommonTools
tz_statusBarHeight
]
;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
toolBarHeight
-
top
:
self
.
view
.
tz_height
-
top
;;
}
else
{
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
50
:
self
.
view
.
tz_height
;
collectionViewHeight
=
tzImagePickerVc
.
showSelectBtn
?
self
.
view
.
tz_height
-
toolBarHeight
:
self
.
view
.
tz_height
;
}
_collectionView
.
frame
=
CGRectMake
(
0
,
top
,
self
.
view
.
tz_width
,
collectionViewHeight
);
CGFloat
itemWH
=
(
self
.
view
.
tz_width
-
(
self
.
columnNumber
+
1
)
*
itemMargin
)
/
self
.
columnNumber
;
...
...
@@ -284,24 +287,24 @@ static CGFloat itemMargin = 5;
[
_collectionView
setContentOffset
:
CGPointMake
(
0
,
offsetY
)];
}
CGFloat
yOffset
=
0
;
CGFloat
toolBarTop
=
0
;
if
(
!
self
.
navigationController
.
navigationBar
.
isHidden
)
{
yOffset
=
self
.
view
.
tz_height
-
50
;
toolBarTop
=
self
.
view
.
tz_height
-
toolBarHeight
;
}
else
{
CGFloat
navigationHeight
=
naviBarHeight
;
if
(
iOS7Later
)
navigationHeight
+=
20
;
yOffset
=
self
.
view
.
tz_height
-
50
-
navigationHeight
;
if
(
iOS7Later
)
navigationHeight
+=
[
TZCommonTools
tz_statusBarHeight
]
;
toolBarTop
=
self
.
view
.
tz_height
-
toolBarHeight
-
navigationHeight
;
}
_bottomToolBar
.
frame
=
CGRectMake
(
0
,
yOffset
,
self
.
view
.
tz_width
,
50
);
CGFloat
previewWidth
=
[
tzImagePickerVc
.
previewBtnTitleStr
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesFontLeading
attributes
:
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
16
]}
context
:
nil
].
size
.
width
+
2
;
_bottomToolBar
.
frame
=
CGRectMake
(
0
,
toolBarTop
,
self
.
view
.
tz_width
,
toolBarHeight
);
CGFloat
previewWidth
=
[
tzImagePickerVc
.
previewBtnTitleStr
tz_calculateSizeWithAttributes
:@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
16
]}
maxSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)]
.
width
+
2
;
if
(
!
tzImagePickerVc
.
allowPreview
)
{
previewWidth
=
0
.
0
;
}
_previewButton
.
frame
=
CGRectMake
(
10
,
3
,
previewWidth
,
44
);
_previewButton
.
tz_width
=
!
tzImagePickerVc
.
showSelectBtn
?
0
:
previewWidth
;
if
(
tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
CGFloat
fullImageWidth
=
[
tzImagePickerVc
.
fullImageBtnTitleStr
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesFontLeading
attributes
:
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
context
:
nil
].
size
.
width
;
_originalPhotoButton
.
frame
=
CGRectMake
(
CGRectGetMaxX
(
_previewButton
.
frame
),
self
.
view
.
tz_height
-
5
0
,
fullImageWidth
+
56
,
50
);
CGFloat
fullImageWidth
=
[
tzImagePickerVc
.
fullImageBtnTitleStr
tz_calculateSizeWithAttributes
:@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
maxSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)]
.
width
;
_originalPhotoButton
.
frame
=
CGRectMake
(
CGRectGetMaxX
(
_previewButton
.
frame
),
0
,
fullImageWidth
+
56
,
50
);
_originalPhotoLabel
.
frame
=
CGRectMake
(
fullImageWidth
+
46
,
0
,
80
,
50
);
}
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
44
-
12
,
3
,
44
,
44
);
...
...
@@ -457,10 +460,13 @@ static CGFloat itemMargin = 5;
__weak
typeof
(
self
)
weakSelf
=
self
;
__weak
typeof
(
_numberImageView
.
layer
)
weakLayer
=
_numberImageView
.
layer
;
cell
.
didSelectPhotoBlock
=
^
(
BOOL
isSelected
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
__strong
typeof
(
weakCell
)
strongCell
=
weakCell
;
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
__strong
typeof
(
weakLayer
)
strongLayer
=
weakLayer
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
strongSelf
.
navigationController
;
// 1. cancel select / 取消选择
if
(
isSelected
)
{
weak
Cell
.
selectPhotoButton
.
selected
=
NO
;
strong
Cell
.
selectPhotoButton
.
selected
=
NO
;
model
.
isSelected
=
NO
;
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
...
...
@@ -469,20 +475,20 @@ static CGFloat itemMargin = 5;
break
;
}
}
[
weak
Self
refreshBottomToolBarStatus
];
[
strong
Self
refreshBottomToolBarStatus
];
}
else
{
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
weak
Cell
.
selectPhotoButton
.
selected
=
YES
;
strong
Cell
.
selectPhotoButton
.
selected
=
YES
;
model
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
weak
Self
refreshBottomToolBarStatus
];
[
strong
Self
refreshBottomToolBarStatus
];
}
else
{
NSString
*
title
=
[
NSString
stringWithFormat
:[
NSBundle
tz_localizedStringForKey
:
@"Select a maximum of %zd photos"
],
tzImagePickerVc
.
maxImagesCount
];
[
tzImagePickerVc
showAlertWithTitle
:
title
];
}
}
[
UIView
showOscillatoryAnimationWithLayer
:
weak
Layer
type
:
TZOscillatoryAnimationToSmaller
];
[
UIView
showOscillatoryAnimationWithLayer
:
strong
Layer
type
:
TZOscillatoryAnimationToSmaller
];
};
return
cell
;
}
...
...
@@ -573,9 +579,11 @@ static CGFloat itemMargin = 5;
// 提前定位
__weak
typeof
(
self
)
weakSelf
=
self
;
[[
TZLocationManager
manager
]
startLocationWithSuccessBlock
:
^
(
CLLocation
*
location
,
CLLocation
*
oldLocation
)
{
weakSelf
.
location
=
location
;
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
strongSelf
.
location
=
location
;
}
failureBlock
:
^
(
NSError
*
error
)
{
weakSelf
.
location
=
nil
;
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
strongSelf
.
location
=
nil
;
}];
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
...
...
@@ -610,16 +618,19 @@ static CGFloat itemMargin = 5;
__weak
typeof
(
self
)
weakSelf
=
self
;
photoPreviewVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
[
photoPreviewVc
setBackButtonClickBlock
:
^
(
BOOL
isSelectOriginalPhoto
)
{
weakSelf
.
isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
weakSelf
.
collectionView
reloadData
];
[
weakSelf
refreshBottomToolBarStatus
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
strongSelf
.
isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
strongSelf
.
collectionView
reloadData
];
[
strongSelf
refreshBottomToolBarStatus
];
}];
[
photoPreviewVc
setDoneButtonClickBlock
:
^
(
BOOL
isSelectOriginalPhoto
)
{
weakSelf
.
isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
weakSelf
doneButtonClick
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
strongSelf
.
isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
strongSelf
doneButtonClick
];
}];
[
photoPreviewVc
setDoneButtonClickBlockCropMode
:
^
(
UIImage
*
cropedImage
,
id
asset
)
{
[
weakSelf
didGetAllPhotos
:@[
cropedImage
]
assets
:@[
asset
]
infoArr
:
nil
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
didGetAllPhotos
:@[
cropedImage
]
assets
:@[
asset
]
infoArr
:
nil
];
}];
[
self
.
navigationController
pushViewController
:
photoPreviewVc
animated
:
YES
];
}
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.h
View file @
8c366ca4
...
...
@@ -11,7 +11,7 @@
@class
TZAssetModel
;
@interface
TZAssetPreviewCell
:
UICollectionViewCell
@property
(
nonatomic
,
strong
)
TZAssetModel
*
model
;
@property
(
nonatomic
,
copy
)
void
(
^
singleTapGestureBlock
)();
@property
(
nonatomic
,
copy
)
void
(
^
singleTapGestureBlock
)(
void
);
-
(
void
)
configSubviews
;
-
(
void
)
photoPreviewCollectionViewDidScroll
;
@end
...
...
@@ -43,7 +43,7 @@
@property
(
nonatomic
,
strong
)
TZAssetModel
*
model
;
@property
(
nonatomic
,
strong
)
id
asset
;
@property
(
nonatomic
,
copy
)
void
(
^
singleTapGestureBlock
)();
@property
(
nonatomic
,
copy
)
void
(
^
singleTapGestureBlock
)(
void
);
@property
(
nonatomic
,
copy
)
void
(
^
imageProgressUpdateBlock
)(
double
progress
);
@property
(
nonatomic
,
assign
)
int32_t
imageRequestID
;
...
...
ios/TZImagePickerController/TZPhotoPreviewCell.m
View file @
8c366ca4
...
...
@@ -50,13 +50,15 @@
self
.
previewView
=
[[
TZPhotoPreviewView
alloc
]
initWithFrame
:
CGRectZero
];
__weak
typeof
(
self
)
weakSelf
=
self
;
[
self
.
previewView
setSingleTapGestureBlock
:
^
{
if
(
weakSelf
.
singleTapGestureBlock
)
{
weakSelf
.
singleTapGestureBlock
();
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
if
(
strongSelf
.
singleTapGestureBlock
)
{
strongSelf
.
singleTapGestureBlock
();
}
}];
[
self
.
previewView
setImageProgressUpdateBlock
:
^
(
double
progress
)
{
if
(
weakSelf
.
imageProgressUpdateBlock
)
{
weakSelf
.
imageProgressUpdateBlock
(
progress
);
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
if
(
strongSelf
.
imageProgressUpdateBlock
)
{
strongSelf
.
imageProgressUpdateBlock
(
progress
);
}
}];
[
self
addSubview
:
self
.
previewView
];
...
...
@@ -387,9 +389,7 @@
if
(
currentTime
.
value
==
durationTime
.
value
)
[
_player
.
currentItem
seekToTime
:
CMTimeMake
(
0
,
1
)];
[
_player
play
];
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
if
(
!
TZ_isGlobalHideStatusBar
&&
iOS7Later
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
self
.
singleTapGestureBlock
)
{
self
.
singleTapGestureBlock
();
}
...
...
@@ -421,7 +421,8 @@
_previewView
=
[[
TZPhotoPreviewView
alloc
]
initWithFrame
:
CGRectZero
];
__weak
typeof
(
self
)
weakSelf
=
self
;
[
_previewView
setSingleTapGestureBlock
:
^
{
[
weakSelf
signleTapAction
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
signleTapAction
];
}];
[
self
addSubview
:
_previewView
];
}
...
...
ios/TZImagePickerController/TZPhotoPreviewController.m
View file @
8c366ca4
...
...
@@ -51,7 +51,6 @@
if
(
!
self
.
models
.
count
)
{
self
.
models
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
_assetsTemp
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
self
.
isSelectOriginalPhoto
=
_tzImagePickerVc
.
isSelectOriginalPhoto
;
}
[
self
configCollectionView
];
[
self
configCustomNaviBar
];
...
...
@@ -68,9 +67,7 @@
-
(
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
animated
:
YES
];
if
(
!
TZ_isGlobalHideStatusBar
)
{
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
_currentIndex
)
[
_collectionView
setContentOffset
:
CGPointMake
((
self
.
view
.
tz_width
+
20
)
*
_currentIndex
,
0
)
animated
:
NO
];
[
self
refreshNaviBarAndBottomBarState
];
}
...
...
@@ -78,8 +75,9 @@
-
(
void
)
viewWillDisappear
:
(
BOOL
)
animated
{
[
super
viewWillDisappear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
NO
animated
:
YES
];
if
(
!
TZ_isGlobalHideStatusBar
)
{
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
needShowStatusBar
&&
iOS7Later
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
[
TZImageManager
manager
].
shouldFixOrientation
=
NO
;
}
...
...
@@ -183,7 +181,7 @@
-
(
void
)
configCropView
{
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
!
_tzImagePickerVc
.
showSelectBtn
&&
_tzImagePickerVc
.
allowCrop
)
{
if
(
_tzImagePickerVc
.
maxImagesCount
<=
1
&&
_tzImagePickerVc
.
allowCrop
)
{
[
_cropView
removeFromSuperview
];
[
_cropBgView
removeFromSuperview
];
...
...
@@ -208,6 +206,9 @@
if
(
_tzImagePickerVc
.
cropViewSettingBlock
)
{
_tzImagePickerVc
.
cropViewSettingBlock
(
_cropView
);
}
[
self
.
view
bringSubviewToFront
:
_naviBar
];
[
self
.
view
bringSubviewToFront
:
_toolBar
];
}
}
...
...
@@ -217,9 +218,12 @@
[
super
viewDidLayoutSubviews
];
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
_naviBar
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
64
);
_backButton
.
frame
=
CGRectMake
(
10
,
10
,
44
,
44
);
_selectButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
54
,
10
,
42
,
42
);
CGFloat
statusBarHeight
=
[
TZCommonTools
tz_statusBarHeight
];
CGFloat
statusBarHeightInterval
=
statusBarHeight
-
20
;
CGFloat
naviBarHeight
=
statusBarHeight
+
_tzImagePickerVc
.
navigationBar
.
tz_height
;
_naviBar
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
naviBarHeight
);
_backButton
.
frame
=
CGRectMake
(
10
,
10
+
statusBarHeightInterval
,
44
,
44
);
_selectButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
54
,
10
+
statusBarHeightInterval
,
42
,
42
);
_layout
.
itemSize
=
CGSizeMake
(
self
.
view
.
tz_width
+
20
,
self
.
view
.
tz_height
);
_layout
.
minimumInteritemSpacing
=
0
;
...
...
@@ -234,9 +238,11 @@
[
_collectionView
reloadData
];
}
_toolBar
.
frame
=
CGRectMake
(
0
,
self
.
view
.
tz_height
-
44
,
self
.
view
.
tz_width
,
44
);
CGFloat
toolBarHeight
=
[
TZCommonTools
tz_isIPhoneX
]
?
44
+
(
83
-
49
)
:
44
;
CGFloat
toolBarTop
=
self
.
view
.
tz_height
-
toolBarHeight
;
_toolBar
.
frame
=
CGRectMake
(
0
,
toolBarTop
,
self
.
view
.
tz_width
,
toolBarHeight
);
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
CGFloat
fullImageWidth
=
[
_tzImagePickerVc
.
fullImageBtnTitleStr
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesFontLeading
attributes
:
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
context
:
nil
].
size
.
width
;
CGFloat
fullImageWidth
=
[
_tzImagePickerVc
.
fullImageBtnTitleStr
tz_calculateSizeWithAttributes
:@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
13
]}
maxSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)]
.
width
;
_originalPhotoButton
.
frame
=
CGRectMake
(
0
,
0
,
fullImageWidth
+
56
,
44
);
_originalPhotoLabel
.
frame
=
CGRectMake
(
fullImageWidth
+
42
,
0
,
80
,
44
);
}
...
...
@@ -420,13 +426,17 @@
__weak
typeof
(
_collectionView
)
weakCollectionView
=
_collectionView
;
__weak
typeof
(
photoPreviewCell
)
weakCell
=
photoPreviewCell
;
[
photoPreviewCell
setImageProgressUpdateBlock
:
^
(
double
progress
)
{
weakSelf
.
progress
=
progress
;
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
__strong
typeof
(
weakTzImagePickerVc
)
strongTzImagePickerVc
=
weakTzImagePickerVc
;
__strong
typeof
(
weakCollectionView
)
strongCollectionView
=
weakCollectionView
;
__strong
typeof
(
weakCell
)
strongCell
=
weakCell
;
strongSelf
.
progress
=
progress
;
if
(
progress
>=
1
)
{
if
(
weakSelf
.
isSelectOriginalPhoto
)
[
weak
Self
showPhotoBytes
];
if
(
weakSelf
.
alertView
&&
[
weakCollectionView
.
visibleCells
containsObject
:
weak
Cell
])
{
[
weakTzImagePickerVc
hideAlertView
:
weak
Self
.
alertView
];
weak
Self
.
alertView
=
nil
;
[
weak
Self
doneButtonClick
];
if
(
strongSelf
.
isSelectOriginalPhoto
)
[
strong
Self
showPhotoBytes
];
if
(
strongSelf
.
alertView
&&
[
strongCollectionView
.
visibleCells
containsObject
:
strong
Cell
])
{
[
strongTzImagePickerVc
hideAlertView
:
strong
Self
.
alertView
];
strong
Self
.
alertView
=
nil
;
[
strong
Self
doneButtonClick
];
}
}
}];
...
...
@@ -434,7 +444,8 @@
cell
.
model
=
model
;
[
cell
setSingleTapGestureBlock
:
^
{
[
weakSelf
didTapPreviewCell
];
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
didTapPreviewCell
];
}];
return
cell
;
}
...
...
ios/TZImagePickerController/TZVideoPlayerController.m
View file @
8c366ca4
...
...
@@ -58,6 +58,9 @@
-
(
void
)
configMoviePlayer
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
_model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
_cover
=
photo
;
if
(
!
isDegraded
&&
photo
)
{
_doneButton
.
enabled
=
YES
;
}
}];
[[
TZImageManager
manager
]
getVideoWithAsset
:
_model
.
asset
completion
:
^
(
AVPlayerItem
*
playerItem
,
NSDictionary
*
info
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
...
...
@@ -101,6 +104,7 @@
_doneButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_doneButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_doneButton
.
enabled
=
NO
;
[
_doneButton
addTarget
:
self
action
:
@selector
(
doneButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
)
{
...
...
@@ -110,6 +114,7 @@
[
_doneButton
setTitle
:[
NSBundle
tz_localizedStringForKey
:
@"Done"
]
forState
:
UIControlStateNormal
];
[
_doneButton
setTitleColor
:[
UIColor
colorWithRed
:(
83
/
255
.
0
)
green
:(
179
/
255
.
0
)
blue
:(
17
/
255
.
0
)
alpha
:
1
.
0
]
forState
:
UIControlStateNormal
];
}
[
_doneButton
setTitleColor
:
tzImagePickerVc
.
oKButtonTitleColorDisabled
forState
:
UIControlStateDisabled
];
[
_toolBar
addSubview
:
_doneButton
];
[
self
.
view
addSubview
:
_toolBar
];
}
...
...
@@ -119,10 +124,13 @@
-
(
void
)
viewDidLayoutSubviews
{
[
super
viewDidLayoutSubviews
];
CGFloat
statusBarHeight
=
[
TZCommonTools
tz_statusBarHeight
];
CGFloat
statusBarAndNaviBarHeight
=
statusBarHeight
+
self
.
navigationController
.
navigationBar
.
tz_height
;
_playerLayer
.
frame
=
self
.
view
.
bounds
;
_playButton
.
frame
=
CGRectMake
(
0
,
64
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
64
-
44
);
CGFloat
toolBarHeight
=
[
TZCommonTools
tz_isIPhoneX
]
?
44
+
(
83
-
49
)
:
44
;
_toolBar
.
frame
=
CGRectMake
(
0
,
self
.
view
.
tz_height
-
toolBarHeight
,
self
.
view
.
tz_width
,
toolBarHeight
);
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
44
-
12
,
0
,
44
,
44
);
_
toolBar
.
frame
=
CGRectMake
(
0
,
self
.
view
.
tz_height
-
44
,
self
.
view
.
tz_width
,
44
);
_
playButton
.
frame
=
CGRectMake
(
0
,
statusBarAndNaviBarHeight
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
statusBarAndNaviBarHeight
-
toolBarHeight
);
}
#pragma mark - Click Event
...
...
@@ -136,9 +144,7 @@
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
_toolBar
.
hidden
=
YES
;
[
_playButton
setImage
:
nil
forState
:
UIControlStateNormal
];
if
(
!
TZ_isGlobalHideStatusBar
)
{
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
}
else
{
[
self
pausePlayerAndShowNaviBar
];
}
...
...
@@ -179,8 +185,9 @@
[
self
.
navigationController
setNavigationBarHidden
:
NO
];
[
_playButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
]
forState
:
UIControlStateNormal
];
if
(
!
TZ_isGlobalHideStatusBar
)
{
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
needShowStatusBar
&&
iOS7Later
)
{
[
UIApplication
sharedApplication
].
statusBarHidden
=
NO
;
}
}
...
...
package.json
View file @
8c366ca4
{
"name"
:
"react-native-syan-image-picker"
,
"version"
:
"0.0.
8
"
,
"version"
:
"0.0.
9
"
,
"description"
:
""
,
"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