Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
a42e994c
Commit
a42e994c
authored
May 14, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开放预览功能,可在外界打开预览界面
parent
6950bfde
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
28 deletions
+98
-28
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
...troller/TZImagePickerController/TZImagePickerController.h
+3
-1
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+24
-1
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+18
-17
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.h
...roller/TZImagePickerController/TZPhotoPreviewController.h
+3
-2
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
...roller/TZImagePickerController/TZPhotoPreviewController.m
+34
-7
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+16
-0
No files found.
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
View file @
a42e994c
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
/// Use this init method / 用这个初始化方法
/// Use this init method / 用这个初始化方法
-
(
instancetype
)
initWithMaxImagesCount
:(
NSInteger
)
maxImagesCount
delegate
:(
id
<
TZImagePickerControllerDelegate
>
)
delegate
;
-
(
instancetype
)
initWithMaxImagesCount
:(
NSInteger
)
maxImagesCount
delegate
:(
id
<
TZImagePickerControllerDelegate
>
)
delegate
;
/// This init method just for previewing photos / 用这个初始化方法以预览图片
-
(
instancetype
)
initWithSelectedAssets
:(
NSMutableArray
*
)
selectedAssets
selectedPhotos
:(
NSMutableArray
*
)
selectedPhotos
index
:(
NSInteger
)
index
;
/// Default is 9 / 默认最大可选9张图片
/// Default is 9 / 默认最大可选9张图片
@property
(
nonatomic
,
assign
)
NSInteger
maxImagesCount
;
@property
(
nonatomic
,
assign
)
NSInteger
maxImagesCount
;
...
@@ -53,7 +55,7 @@
...
@@ -53,7 +55,7 @@
/// The photos user have selected
/// The photos user have selected
/// 用户选中过的图片数组
/// 用户选中过的图片数组
@property
(
nonatomic
,
strong
)
NSArray
*
selectedAssets
;
@property
(
nonatomic
,
strong
)
NS
Mutable
Array
*
selectedAssets
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
TZAssetModel
*>
*
selectedModels
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
TZAssetModel
*>
*
selectedModels
;
-
(
void
)
showAlertWithTitle
:(
NSString
*
)
title
;
-
(
void
)
showAlertWithTitle
:(
NSString
*
)
title
;
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
a42e994c
...
@@ -108,6 +108,29 @@
...
@@ -108,6 +108,29 @@
return
self
;
return
self
;
}
}
/// This init method just for previewing photos / 用这个初始化方法以预览图片
-
(
instancetype
)
initWithSelectedAssets
:(
NSMutableArray
*
)
selectedAssets
selectedPhotos
:(
NSMutableArray
*
)
selectedPhotos
index
:(
NSInteger
)
index
{
TZPhotoPreviewController
*
previewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
self
=
[
super
initWithRootViewController
:
previewVc
];
if
(
self
)
{
self
.
selectedAssets
=
selectedAssets
;
self
.
allowPickingOriginalPhoto
=
YES
;
self
.
timeout
=
15
;
self
.
photoWidth
=
828
.
0
;
self
.
maxImagesCount
=
selectedAssets
.
count
;
previewVc
.
photos
=
[
NSMutableArray
arrayWithArray
:
selectedPhotos
];
previewVc
.
currentIndex
=
index
;
[
previewVc
setOkButtonClickBlockWithPreviewType
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
if
(
self
.
didFinishPickingPhotosHandle
)
{
self
.
didFinishPickingPhotosHandle
(
photos
,
assets
,
isSelectOriginalPhoto
);
}
[
self
dismissViewControllerAnimated
:
YES
completion
:
nil
];
}];
}
return
self
;
}
-
(
void
)
observeAuthrizationStatusChange
{
-
(
void
)
observeAuthrizationStatusChange
{
if
([[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
if
([[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
[
self
pushToPhotoPickerVc
];
[
self
pushToPhotoPickerVc
];
...
@@ -190,7 +213,7 @@
...
@@ -190,7 +213,7 @@
}
}
}
}
-
(
void
)
setSelectedAssets
:(
NSArray
*
)
selectedAssets
{
-
(
void
)
setSelectedAssets
:(
NS
Mutable
Array
*
)
selectedAssets
{
_selectedAssets
=
selectedAssets
;
_selectedAssets
=
selectedAssets
;
_selectedModels
=
[
NSMutableArray
array
];
_selectedModels
=
[
NSMutableArray
array
];
for
(
id
asset
in
selectedAssets
)
{
for
(
id
asset
in
selectedAssets
)
{
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
a42e994c
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#import "TZVideoPlayerController.h"
#import "TZVideoPlayerController.h"
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
>
{
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
>
{
NSMutableArray
*
_
photoArr
;
NSMutableArray
*
_
models
;
UIButton
*
_previewButton
;
UIButton
*
_previewButton
;
UIButton
*
_okButton
;
UIButton
*
_okButton
;
...
@@ -68,11 +68,11 @@ static CGSize AssetGridThumbnailSize;
...
@@ -68,11 +68,11 @@ static CGSize AssetGridThumbnailSize;
self
.
navigationItem
.
rightBarButtonItem
=
[[
UIBarButtonItem
alloc
]
initWithTitle
:
@"取消"
style
:
UIBarButtonItemStylePlain
target
:
self
action
:
@selector
(
cancel
)];
self
.
navigationItem
.
rightBarButtonItem
=
[[
UIBarButtonItem
alloc
]
initWithTitle
:
@"取消"
style
:
UIBarButtonItemStylePlain
target
:
self
action
:
@selector
(
cancel
)];
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
||
!
iOS8Later
)
{
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
||
!
iOS8Later
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
_
photoArr
=
[
NSMutableArray
arrayWithArray
:
models
];
_
models
=
[
NSMutableArray
arrayWithArray
:
models
];
[
self
initSubviews
];
[
self
initSubviews
];
}];
}];
}
else
{
}
else
{
_
photoArr
=
[
NSMutableArray
arrayWithArray
:
_model
.
models
];
_
models
=
[
NSMutableArray
arrayWithArray
:
_model
.
models
];
[
self
initSubviews
];
[
self
initSubviews
];
}
}
// [self resetCachedAssets];
// [self resetCachedAssets];
...
@@ -228,9 +228,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -228,9 +228,7 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
previewButtonClick
{
-
(
void
)
previewButtonClick
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
photoPreviewVc
.
photoArr
=
[
NSArray
arrayWithArray
:
tzImagePickerVc
.
selectedModels
];
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
}
}
...
@@ -287,22 +285,22 @@ static CGSize AssetGridThumbnailSize;
...
@@ -287,22 +285,22 @@ static CGSize AssetGridThumbnailSize;
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
allowPickingImage
)
{
if
(
tzImagePickerVc
.
allowPickingImage
)
{
return
_
photoArr
.
count
+
1
;
return
_
models
.
count
+
1
;
}
}
}
}
return
_
photoArr
.
count
;
return
_
models
.
count
;
}
}
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// the cell lead to take a picture / 去拍照的cell
// the cell lead to take a picture / 去拍照的cell
if
(
indexPath
.
row
>=
_
photoArr
.
count
)
{
if
(
indexPath
.
row
>=
_
models
.
count
)
{
TZAssetCameraCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCameraCell"
forIndexPath
:
indexPath
];
TZAssetCameraCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCameraCell"
forIndexPath
:
indexPath
];
cell
.
imageView
.
image
=
[
UIImage
imageNamedFromMyBundle
:
@"takePicture.png"
];
cell
.
imageView
.
image
=
[
UIImage
imageNamedFromMyBundle
:
@"takePicture.png"
];
return
cell
;
return
cell
;
}
}
// the cell dipaly photo or video / 展示照片或视频的cell
// the cell dipaly photo or video / 展示照片或视频的cell
TZAssetCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCell"
forIndexPath
:
indexPath
];
TZAssetCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCell"
forIndexPath
:
indexPath
];
TZAssetModel
*
model
=
_
photoArr
[
indexPath
.
row
];
TZAssetModel
*
model
=
_
models
[
indexPath
.
row
];
cell
.
model
=
model
;
cell
.
model
=
model
;
__weak
typeof
(
cell
)
weakCell
=
cell
;
__weak
typeof
(
cell
)
weakCell
=
cell
;
...
@@ -339,11 +337,11 @@ static CGSize AssetGridThumbnailSize;
...
@@ -339,11 +337,11 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// take a picture / 去拍照
// take a picture / 去拍照
if
(
indexPath
.
row
>=
_
photoArr
.
count
)
{
if
(
indexPath
.
row
>=
_
models
.
count
)
{
[
self
takePicture
];
return
;
[
self
takePicture
];
return
;
}
}
// preview phote or video / 预览照片或视频
// preview phote or video / 预览照片或视频
TZAssetModel
*
model
=
_
photoArr
[
indexPath
.
row
];
TZAssetModel
*
model
=
_
models
[
indexPath
.
row
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
tzImagePickerVc
.
selectedModels
.
count
>
0
)
{
if
(
tzImagePickerVc
.
selectedModels
.
count
>
0
)
{
...
@@ -356,8 +354,8 @@ static CGSize AssetGridThumbnailSize;
...
@@ -356,8 +354,8 @@ static CGSize AssetGridThumbnailSize;
}
}
}
else
{
}
else
{
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
photoPreviewVc
.
photoArr
=
_photoArr
;
photoPreviewVc
.
currentIndex
=
indexPath
.
row
;
photoPreviewVc
.
currentIndex
=
indexPath
.
row
;
photoPreviewVc
.
models
=
_models
;
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
}
}
}
}
...
@@ -426,6 +424,9 @@ static CGSize AssetGridThumbnailSize;
...
@@ -426,6 +424,9 @@ static CGSize AssetGridThumbnailSize;
/// Scale image / 缩放图片
/// Scale image / 缩放图片
-
(
UIImage
*
)
scaleImage
:(
UIImage
*
)
image
toSize
:(
CGSize
)
size
{
-
(
UIImage
*
)
scaleImage
:(
UIImage
*
)
image
toSize
:(
CGSize
)
size
{
if
(
image
.
size
.
width
<
size
.
width
)
{
return
image
;
}
UIGraphicsBeginImageContext
(
size
);
UIGraphicsBeginImageContext
(
size
);
[
image
drawInRect
:
CGRectMake
(
0
,
0
,
size
.
width
,
size
.
height
)];
[
image
drawInRect
:
CGRectMake
(
0
,
0
,
size
.
width
,
size
.
height
)];
UIImage
*
newImage
=
UIGraphicsGetImageFromCurrentImageContext
();
UIImage
*
newImage
=
UIGraphicsGetImageFromCurrentImageContext
();
...
@@ -434,8 +435,8 @@ static CGSize AssetGridThumbnailSize;
...
@@ -434,8 +435,8 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
scrollCollectionViewToBottom
{
-
(
void
)
scrollCollectionViewToBottom
{
if
(
_shouldScrollToBottom
&&
_
photoArr
.
count
>
0
)
{
if
(
_shouldScrollToBottom
&&
_
models
.
count
>
0
)
{
NSInteger
item
=
_
photoArr
.
count
-
1
;
NSInteger
item
=
_
models
.
count
-
1
;
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
allowPickingImage
)
{
if
(
tzImagePickerVc
.
allowPickingImage
)
{
...
@@ -448,7 +449,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -448,7 +449,7 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
checkSelectedModels
{
-
(
void
)
checkSelectedModels
{
for
(
TZAssetModel
*
model
in
_
photoArr
)
{
for
(
TZAssetModel
*
model
in
_
models
)
{
model
.
isSelected
=
NO
;
model
.
isSelected
=
NO
;
NSMutableArray
*
selectedAssets
=
[
NSMutableArray
array
];
NSMutableArray
*
selectedAssets
=
[
NSMutableArray
array
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
...
@@ -484,7 +485,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -484,7 +485,7 @@ static CGSize AssetGridThumbnailSize;
[
tzImagePickerVc
hideProgressHUD
];
[
tzImagePickerVc
hideProgressHUD
];
TZAssetModel
*
model
=
[
models
lastObject
];
TZAssetModel
*
model
=
[
models
lastObject
];
[
_
photoArr
addObject
:
model
];
[
_
models
addObject
:
model
];
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
model
.
isSelected
=
YES
;
model
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
tzImagePickerVc
.
selectedModels
addObject
:
model
];
...
@@ -591,7 +592,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -591,7 +592,7 @@ static CGSize AssetGridThumbnailSize;
NSMutableArray
*
assets
=
[
NSMutableArray
arrayWithCapacity
:
indexPaths
.
count
];
NSMutableArray
*
assets
=
[
NSMutableArray
arrayWithCapacity
:
indexPaths
.
count
];
for
(
NSIndexPath
*
indexPath
in
indexPaths
)
{
for
(
NSIndexPath
*
indexPath
in
indexPaths
)
{
TZAssetModel
*
model
=
_
photoArr
[
indexPath
.
item
];
TZAssetModel
*
model
=
_
models
[
indexPath
.
item
];
[
assets
addObject
:
model
.
asset
];
[
assets
addObject
:
model
.
asset
];
}
}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.h
View file @
a42e994c
...
@@ -10,13 +10,14 @@
...
@@ -10,13 +10,14 @@
@interface
TZPhotoPreviewController
:
UIViewController
@interface
TZPhotoPreviewController
:
UIViewController
@property
(
nonatomic
,
strong
)
NS
Array
*
photoArr
;
///< All photos / 所有图片的
数组
@property
(
nonatomic
,
strong
)
NS
MutableArray
*
models
;
///< All photo models / 所有图片模型
数组
// @property (nonatomic, strong) NSMutableArray *selectedPhotoArr; ///< Current selected photos / 当前选中的
图片数组
@property
(
nonatomic
,
strong
)
NSMutableArray
*
photos
;
///< All photos / 所有
图片数组
@property
(
nonatomic
,
assign
)
NSInteger
currentIndex
;
///< Index of the photo user click / 用户点击的图片的索引
@property
(
nonatomic
,
assign
)
NSInteger
currentIndex
;
///< Index of the photo user click / 用户点击的图片的索引
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
///< If YES,return original photo / 是否返回原图
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
///< If YES,return original photo / 是否返回原图
/// Return the new selected photos / 返回最新的选中图片数组
/// Return the new selected photos / 返回最新的选中图片数组
@property
(
nonatomic
,
copy
)
void
(
^
backButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
backButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
okButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
okButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
okButtonClickBlockWithPreviewType
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
);
@end
@end
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
View file @
a42e994c
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
@interface
TZPhotoPreviewController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIScrollViewDelegate
>
{
@interface
TZPhotoPreviewController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIScrollViewDelegate
>
{
UICollectionView
*
_collectionView
;
UICollectionView
*
_collectionView
;
BOOL
_isHideNaviBar
;
BOOL
_isHideNaviBar
;
NSArray
*
_photosTemp
;
NSArray
*
_assetsTemp
;
UIView
*
_naviBar
;
UIView
*
_naviBar
;
UIButton
*
_backButton
;
UIButton
*
_backButton
;
...
@@ -37,11 +39,21 @@
...
@@ -37,11 +39,21 @@
[
super
viewDidLoad
];
[
super
viewDidLoad
];
__weak
typeof
(
self
)
weakSelf
=
self
;
__weak
typeof
(
self
)
weakSelf
=
self
;
_tzImagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
_tzImagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
if
(
!
self
.
models
.
count
)
{
self
.
models
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
_assetsTemp
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
self
.
isSelectOriginalPhoto
=
_tzImagePickerVc
.
isSelectOriginalPhoto
;
}
[
self
configCollectionView
];
[
self
configCollectionView
];
[
self
configCustomNaviBar
];
[
self
configCustomNaviBar
];
[
self
configBottomToolBar
];
[
self
configBottomToolBar
];
}
}
-
(
void
)
setPhotos
:(
NSMutableArray
*
)
photos
{
_photos
=
photos
;
_photosTemp
=
[
NSArray
arrayWithArray
:
photos
];
}
-
(
void
)
viewWillAppear
:(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
...
@@ -149,7 +161,7 @@
...
@@ -149,7 +161,7 @@
_collectionView
.
scrollsToTop
=
NO
;
_collectionView
.
scrollsToTop
=
NO
;
_collectionView
.
showsHorizontalScrollIndicator
=
NO
;
_collectionView
.
showsHorizontalScrollIndicator
=
NO
;
_collectionView
.
contentOffset
=
CGPointMake
(
0
,
0
);
_collectionView
.
contentOffset
=
CGPointMake
(
0
,
0
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
*
_
photoArr
.
count
,
self
.
view
.
tz_height
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
*
_
models
.
count
,
self
.
view
.
tz_height
);
[
self
.
view
addSubview
:
_collectionView
];
[
self
.
view
addSubview
:
_collectionView
];
[
_collectionView
registerClass
:[
TZPhotoPreviewCell
class
]
forCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
];
[
_collectionView
registerClass
:[
TZPhotoPreviewCell
class
]
forCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
];
}
}
...
@@ -157,7 +169,7 @@
...
@@ -157,7 +169,7 @@
#pragma mark - Click Event
#pragma mark - Click Event
-
(
void
)
select
:(
UIButton
*
)
selectButton
{
-
(
void
)
select
:(
UIButton
*
)
selectButton
{
TZAssetModel
*
model
=
_
photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_
models
[
_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
)
{
...
@@ -166,6 +178,10 @@
...
@@ -166,6 +178,10 @@
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制
}
else
{
}
else
{
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
if
(
self
.
photos
)
{
[
self
.
tzImagePickerVc
.
selectedAssets
addObject
:
_assetsTemp
[
_currentIndex
]];
[
self
.
photos
addObject
:
_photosTemp
[
_currentIndex
]];
}
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
[
_tzImagePickerVc
showAlertWithTitle
:
@"多选状态下选择视频,默认将视频当图片发送"
];
[
_tzImagePickerVc
showAlertWithTitle
:
@"多选状态下选择视频,默认将视频当图片发送"
];
}
}
...
@@ -175,6 +191,10 @@
...
@@ -175,6 +191,10 @@
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([
model
.
asset
isEqual
:
model_item
.
asset
])
{
if
([
model
.
asset
isEqual
:
model_item
.
asset
])
{
[
self
.
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
[
self
.
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
if
(
self
.
photos
)
{
[
self
.
tzImagePickerVc
.
selectedAssets
removeObject
:
_assetsTemp
[
_currentIndex
]];
[
self
.
photos
removeObject
:
_photosTemp
[
_currentIndex
]];
}
}
}
}
}
}
}
...
@@ -187,6 +207,10 @@
...
@@ -187,6 +207,10 @@
}
}
-
(
void
)
back
{
-
(
void
)
back
{
if
(
self
.
navigationController
.
childViewControllers
.
count
<
2
)
{
[
self
.
navigationController
dismissViewControllerAnimated
:
YES
completion
:
nil
];
return
;
}
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
if
(
self
.
backButtonClickBlock
)
{
if
(
self
.
backButtonClickBlock
)
{
self
.
backButtonClickBlock
(
_isSelectOriginalPhoto
);
self
.
backButtonClickBlock
(
_isSelectOriginalPhoto
);
...
@@ -195,12 +219,15 @@
...
@@ -195,12 +219,15 @@
-
(
void
)
okButtonClick
{
-
(
void
)
okButtonClick
{
if
(
_tzImagePickerVc
.
selectedModels
.
count
==
0
)
{
if
(
_tzImagePickerVc
.
selectedModels
.
count
==
0
)
{
TZAssetModel
*
model
=
_
photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_
models
[
_currentIndex
];
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
}
}
if
(
self
.
okButtonClickBlock
)
{
if
(
self
.
okButtonClickBlock
)
{
self
.
okButtonClickBlock
(
_isSelectOriginalPhoto
);
self
.
okButtonClickBlock
(
_isSelectOriginalPhoto
);
}
}
if
(
self
.
okButtonClickBlockWithPreviewType
)
{
self
.
okButtonClickBlockWithPreviewType
(
self
.
photos
,
self
.
tzImagePickerVc
.
selectedAssets
,
self
.
isSelectOriginalPhoto
);
}
}
}
-
(
void
)
originalPhotoButtonClick
{
-
(
void
)
originalPhotoButtonClick
{
...
@@ -224,12 +251,12 @@
...
@@ -224,12 +251,12 @@
#pragma mark - UICollectionViewDataSource && Delegate
#pragma mark - UICollectionViewDataSource && Delegate
-
(
NSInteger
)
collectionView
:(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:(
NSInteger
)
section
{
-
(
NSInteger
)
collectionView
:(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:(
NSInteger
)
section
{
return
_
photoArr
.
count
;
return
_
models
.
count
;
}
}
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
TZPhotoPreviewCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
forIndexPath
:
indexPath
];
TZPhotoPreviewCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
forIndexPath
:
indexPath
];
cell
.
model
=
_
photoArr
[
indexPath
.
row
];
cell
.
model
=
_
models
[
indexPath
.
row
];
__block
BOOL
_weakIsHideNaviBar
=
_isHideNaviBar
;
__block
BOOL
_weakIsHideNaviBar
=
_isHideNaviBar
;
__weak
typeof
(
_naviBar
)
weakNaviBar
=
_naviBar
;
__weak
typeof
(
_naviBar
)
weakNaviBar
=
_naviBar
;
...
@@ -248,7 +275,7 @@
...
@@ -248,7 +275,7 @@
#pragma mark - Private Method
#pragma mark - Private Method
-
(
void
)
refreshNaviBarAndBottomBarState
{
-
(
void
)
refreshNaviBarAndBottomBarState
{
TZAssetModel
*
model
=
_
photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_
models
[
_currentIndex
];
_selectButton
.
selected
=
model
.
isSelected
;
_selectButton
.
selected
=
model
.
isSelected
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_tzImagePickerVc
.
selectedModels
.
count
];
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_tzImagePickerVc
.
selectedModels
.
count
];
_numberImageView
.
hidden
=
(
_tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
);
_numberImageView
.
hidden
=
(
_tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
);
...
@@ -271,7 +298,7 @@
...
@@ -271,7 +298,7 @@
}
}
-
(
void
)
showPhotoBytes
{
-
(
void
)
showPhotoBytes
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:@[
_
photoArr
[
_currentIndex
]]
completion
:
^
(
NSString
*
totalBytes
)
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:@[
_
models
[
_currentIndex
]]
completion
:
^
(
NSString
*
totalBytes
)
{
_originalPhotoLable
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
_originalPhotoLable
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
}];
}];
}
}
...
...
TZImagePickerController/ViewController.m
View file @
a42e994c
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
@interface
ViewController
()
<
TZImagePickerControllerDelegate
,
UICollectionViewDataSource
,
UICollectionViewDelegate
>
{
@interface
ViewController
()
<
TZImagePickerControllerDelegate
,
UICollectionViewDataSource
,
UICollectionViewDelegate
>
{
NSMutableArray
*
_selectedPhotos
;
NSMutableArray
*
_selectedPhotos
;
NSMutableArray
*
_selectedAssets
;
NSMutableArray
*
_selectedAssets
;
BOOL
_isSelectOriginalPhoto
;
CGFloat
_itemWH
;
CGFloat
_itemWH
;
CGFloat
_margin
;
CGFloat
_margin
;
...
@@ -77,6 +78,19 @@
...
@@ -77,6 +78,19 @@
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
if
(
indexPath
.
row
==
_selectedPhotos
.
count
)
{
if
(
indexPath
.
row
==
_selectedPhotos
.
count
)
{
[
self
pickPhotoButtonClick
:
nil
];
[
self
pickPhotoButtonClick
:
nil
];
}
else
{
// preview photos / 预览照片
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithSelectedAssets
:
_selectedAssets
selectedPhotos
:
_selectedPhotos
index
:
indexPath
.
row
];
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
// imagePickerVc.allowPickingOriginalPhoto = NO;
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
_layout
.
itemCount
=
_selectedPhotos
.
count
;
[
_collectionView
reloadData
];
_collectionView
.
contentSize
=
CGSizeMake
(
0
,
((
_selectedPhotos
.
count
+
2
)
/
3
)
*
(
_margin
+
_itemWH
));
}];
[
self
presentViewController
:
imagePickerVc
animated
:
YES
completion
:
nil
];
}
}
}
}
...
@@ -107,6 +121,7 @@
...
@@ -107,6 +121,7 @@
-
(
IBAction
)
pickPhotoButtonClick
:(
UIButton
*
)
sender
{
-
(
IBAction
)
pickPhotoButtonClick
:(
UIButton
*
)
sender
{
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
9
delegate
:
self
];
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
9
delegate
:
self
];
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
imagePickerVc
.
selectedAssets
=
_selectedAssets
;
// optional, 可选的
imagePickerVc
.
selectedAssets
=
_selectedAssets
;
// optional, 可选的
// You can get the photos by block, the same as by delegate.
// You can get the photos by block, the same as by delegate.
...
@@ -143,6 +158,7 @@
...
@@ -143,6 +158,7 @@
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
{
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
{
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
_layout
.
itemCount
=
_selectedPhotos
.
count
;
_layout
.
itemCount
=
_selectedPhotos
.
count
;
[
_collectionView
reloadData
];
[
_collectionView
reloadData
];
_collectionView
.
contentSize
=
CGSizeMake
(
0
,
((
_selectedPhotos
.
count
+
2
)
/
3
)
*
(
_margin
+
_itemWH
));
_collectionView
.
contentSize
=
CGSizeMake
(
0
,
((
_selectedPhotos
.
count
+
2
)
/
3
)
*
(
_margin
+
_itemWH
));
...
...
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