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
a567b512
Commit
a567b512
authored
Apr 24, 2016
by
tanzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入拍照功能;优化显示效果,可全局显示已选中的图片,切换相册亦可,设置selectedAssets即可显示上次已选中的图片。
parent
55864229
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
418 additions
and
130 deletions
+418
-130
TZImagePickerController/TZImagePickerController/TZAssetCell.h
...agePickerController/TZImagePickerController/TZAssetCell.h
+9
-1
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+46
-1
TZImagePickerController/TZImagePickerController/TZAssetModel.h
...gePickerController/TZImagePickerController/TZAssetModel.h
+3
-0
TZImagePickerController/TZImagePickerController/TZAssetModel.m
...gePickerController/TZImagePickerController/TZAssetModel.m
+32
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+0
-2
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/takePicture@2x.png
...troller/TZImagePickerController.bundle/takePicture@2x.png
+0
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
...troller/TZImagePickerController/TZImagePickerController.h
+24
-9
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+63
-18
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.h
...troller/TZImagePickerController/TZPhotoPickerController.h
+1
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+205
-62
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.h
...roller/TZImagePickerController/TZPhotoPreviewController.h
+3
-3
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
...roller/TZImagePickerController/TZPhotoPreviewController.m
+27
-31
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+5
-3
No files found.
TZImagePickerController/TZImagePickerController/TZAssetCell.h
View file @
a567b512
...
@@ -18,7 +18,7 @@ typedef enum : NSUInteger {
...
@@ -18,7 +18,7 @@ typedef enum : NSUInteger {
@class
TZAssetModel
;
@class
TZAssetModel
;
@interface
TZAssetCell
:
UICollectionViewCell
@interface
TZAssetCell
:
UICollectionViewCell
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
selectPhotoButton
;
@property
(
weak
,
nonatomic
)
UIButton
*
selectPhotoButton
;
@property
(
nonatomic
,
strong
)
TZAssetModel
*
model
;
@property
(
nonatomic
,
strong
)
TZAssetModel
*
model
;
@property
(
nonatomic
,
copy
)
void
(
^
didSelectPhotoBlock
)(
BOOL
);
@property
(
nonatomic
,
copy
)
void
(
^
didSelectPhotoBlock
)(
BOOL
);
@property
(
nonatomic
,
assign
)
TZAssetCellType
type
;
@property
(
nonatomic
,
assign
)
TZAssetCellType
type
;
...
@@ -31,5 +31,13 @@ typedef enum : NSUInteger {
...
@@ -31,5 +31,13 @@ typedef enum : NSUInteger {
@interface
TZAlbumCell
:
UITableViewCell
@interface
TZAlbumCell
:
UITableViewCell
@property
(
nonatomic
,
strong
)
TZAlbumModel
*
model
;
@property
(
nonatomic
,
strong
)
TZAlbumModel
*
model
;
@property
(
weak
,
nonatomic
)
UIButton
*
selectedCountButton
;
@end
@end
@interface
TZAssetCameraCell
:
UICollectionViewCell
@property
(
nonatomic
,
strong
)
UIImageView
*
imageView
;
@end
\ No newline at end of file
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
a567b512
...
@@ -169,11 +169,18 @@
...
@@ -169,11 +169,18 @@
[[
TZImageManager
manager
]
getPostImageWithAlbumModel
:
model
completion
:
^
(
UIImage
*
postImage
)
{
[[
TZImageManager
manager
]
getPostImageWithAlbumModel
:
model
completion
:
^
(
UIImage
*
postImage
)
{
self
.
posterImageView
.
image
=
postImage
;
self
.
posterImageView
.
image
=
postImage
;
}];
}];
if
(
model
.
selectedCount
)
{
self
.
selectedCountButton
.
hidden
=
NO
;
[
self
.
selectedCountButton
setTitle
:[
NSString
stringWithFormat
:
@"%zd"
,
model
.
selectedCount
]
forState
:
UIControlStateNormal
];
}
else
{
self
.
selectedCountButton
.
hidden
=
YES
;
}
}
}
/// For fitting iOS6
/// For fitting iOS6
-
(
void
)
layoutSubviews
{
-
(
void
)
layoutSubviews
{
if
(
iOS7Later
)
[
super
layoutSubviews
];
if
(
iOS7Later
)
[
super
layoutSubviews
];
_selectedCountButton
.
frame
=
CGRectMake
(
self
.
tz_width
-
24
-
30
,
23
,
24
,
24
);
}
}
-
(
void
)
layoutSublayersOfLayer
:(
CALayer
*
)
layer
{
-
(
void
)
layoutSublayersOfLayer
:(
CALayer
*
)
layer
{
...
@@ -219,4 +226,42 @@
...
@@ -219,4 +226,42 @@
return
_arrowImageView
;
return
_arrowImageView
;
}
}
@end
-
(
UIButton
*
)
selectedCountButton
{
\ No newline at end of file
if
(
_selectedCountButton
==
nil
)
{
UIButton
*
selectedCountButton
=
[[
UIButton
alloc
]
init
];
selectedCountButton
.
layer
.
cornerRadius
=
12
;
selectedCountButton
.
clipsToBounds
=
YES
;
selectedCountButton
.
backgroundColor
=
[
UIColor
redColor
];
[
selectedCountButton
setTitleColor
:[
UIColor
whiteColor
]
forState
:
UIControlStateNormal
];
selectedCountButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
15
];
[
self
.
contentView
addSubview
:
selectedCountButton
];
_selectedCountButton
=
selectedCountButton
;
}
return
_selectedCountButton
;
}
@end
@implementation
TZAssetCameraCell
-
(
instancetype
)
initWithFrame
:(
CGRect
)
frame
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
self
.
backgroundColor
=
[
UIColor
whiteColor
];
_imageView
=
[[
UIImageView
alloc
]
init
];
_imageView
.
backgroundColor
=
[
UIColor
colorWithWhite
:
1
.
000
alpha
:
0
.
500
];
_imageView
.
contentMode
=
UIViewContentModeScaleAspectFill
;
[
self
addSubview
:
_imageView
];
self
.
clipsToBounds
=
YES
;
}
return
self
;
}
-
(
void
)
layoutSubviews
{
[
super
layoutSubviews
];
_imageView
.
frame
=
self
.
bounds
;
}
@end
TZImagePickerController/TZImagePickerController/TZAssetModel.h
View file @
a567b512
...
@@ -39,4 +39,7 @@ typedef enum : NSUInteger {
...
@@ -39,4 +39,7 @@ typedef enum : NSUInteger {
@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
)
id
result
;
///< PHFetchResult<PHAsset> or ALAssetsGroup<ALAsset>
@property
(
nonatomic
,
strong
)
NSArray
*
models
;
@property
(
nonatomic
,
strong
)
NSArray
*
selectedModels
;
@property
(
nonatomic
,
assign
)
NSUInteger
selectedCount
;
@end
@end
\ No newline at end of file
TZImagePickerController/TZImagePickerController/TZAssetModel.m
View file @
a567b512
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
//
//
#import "TZAssetModel.h"
#import "TZAssetModel.h"
#import "TZImageManager.h"
@implementation
TZAssetModel
@implementation
TZAssetModel
...
@@ -30,5 +31,36 @@
...
@@ -30,5 +31,36 @@
@implementation
TZAlbumModel
@implementation
TZAlbumModel
-
(
void
)
setResult
:(
id
)
result
{
_result
=
result
;
BOOL
allowPickingImage
=
[[[
NSUserDefaults
standardUserDefaults
]
objectForKey
:
@"tz_allowPickingImage"
]
isEqualToString
:
@"1"
];
BOOL
allowPickingVideo
=
[[[
NSUserDefaults
standardUserDefaults
]
objectForKey
:
@"tz_allowPickingVideo"
]
isEqualToString
:
@"1"
];
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
result
allowPickingVideo
:
allowPickingVideo
allowPickingImage
:
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
_models
=
models
;
if
(
_selectedModels
)
{
[
self
checkSelectedModels
];
}
}];
}
-
(
void
)
setSelectedModels
:(
NSArray
*
)
selectedModels
{
_selectedModels
=
selectedModels
;
if
(
_models
)
{
[
self
checkSelectedModels
];
}
}
-
(
void
)
checkSelectedModels
{
self
.
selectedCount
=
0
;
NSMutableArray
*
selectedAssets
=
[
NSMutableArray
array
];
for
(
TZAssetModel
*
model
in
_selectedModels
)
{
[
selectedAssets
addObject
:
model
.
asset
];
}
for
(
TZAssetModel
*
model
in
_models
)
{
if
([
selectedAssets
containsObject
:
model
.
asset
])
{
self
.
selectedCount
++
;
}
}
}
@end
@end
\ No newline at end of file
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
a567b512
...
@@ -54,8 +54,6 @@
...
@@ -54,8 +54,6 @@
PHAssetMediaTypeVideo
];
PHAssetMediaTypeVideo
];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"creationDate"
ascending
:
YES
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"creationDate"
ascending
:
YES
]];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeSmartAlbumUserLibrary
options
:
nil
];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeSmartAlbumUserLibrary
options
:
nil
];
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
])
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
])
{
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle/takePicture@2x.png
0 → 100644
View file @
a567b512
5.79 KB
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
View file @
a567b512
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
*/
*/
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#import "TZAssetModel.h"
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
...
@@ -50,20 +51,30 @@
...
@@ -50,20 +51,30 @@
/// 默认为YES,如果设置为NO,用户将不能选择发送图片
/// 默认为YES,如果设置为NO,用户将不能选择发送图片
@property
(
nonatomic
,
assign
)
BOOL
allowPickingImage
;
@property
(
nonatomic
,
assign
)
BOOL
allowPickingImage
;
/// The photos user have selected
/// 用户选中过的图片数组
@property
(
nonatomic
,
strong
)
NSArray
*
selectedAssets
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
TZAssetModel
*>
*
selectedModels
;
-
(
void
)
showAlertWithTitle
:(
NSString
*
)
title
;
-
(
void
)
showAlertWithTitle
:(
NSString
*
)
title
;
-
(
void
)
showProgressHUD
;
-
(
void
)
showProgressHUD
;
-
(
void
)
hideProgressHUD
;
-
(
void
)
hideProgressHUD
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
/// Appearance / 外观颜色
/// Appearance / 外观颜色
@property
(
nonatomic
,
strong
)
UIColor
*
oKButtonTitleColorNormal
;
@property
(
nonatomic
,
strong
)
UIColor
*
oKButtonTitleColorNormal
;
@property
(
nonatomic
,
strong
)
UIColor
*
oKButtonTitleColorDisabled
;
@property
(
nonatomic
,
strong
)
UIColor
*
oKButtonTitleColorDisabled
;
// The picker should dismiss itself; when it dismissed these handle will be called.
// The picker should dismiss itself; when it dismissed these handle will be called.
// The second array will be a empty array if user not picking original photo.
// If isOriginalPhoto is YES, user picked the original photo.
// You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
// The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
// 如果用户没有选择发送原图,第二个数组将是空数组
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
);
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
@property
(
nonatomic
,
copy
)
void
(
^
didFinishPickingPhotosWithInfosHandle
)(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
NSArray
<
NSDictionary
*>
*
infos
);
// 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
)();
// 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.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
...
@@ -79,11 +90,15 @@
...
@@ -79,11 +90,15 @@
@protocol
TZImagePickerControllerDelegate
<
NSObject
>
@protocol
TZImagePickerControllerDelegate
<
NSObject
>
@optional
@optional
// The picker should dismiss itself; when it dismissed these handle will be called.
// The picker should dismiss itself; when it dismissed these handle will be called.
// Assets will be a empty array if user not picking original photo.
// If isOriginalPhoto is YES, user picked the original photo.
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的回调
// You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
// 如果用户没有选择发送原图,Assets将是空数组
// The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
;
// 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
infos
:(
NSArray
<
NSDictionary
*>
*
)
infos
;
// 如果isSelectOriginalPhoto为YES,表明用户选择了原图
// 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
// photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
;
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
<
UIImage
*>
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
infos
:(
NSArray
<
NSDictionary
*>
*
)
infos
;
-
(
void
)
imagePickerControllerDidCancel
:(
TZImagePickerController
*
)
picker
;
-
(
void
)
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.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
a567b512
...
@@ -78,13 +78,15 @@
...
@@ -78,13 +78,15 @@
if
(
self
)
{
if
(
self
)
{
self
.
maxImagesCount
=
maxImagesCount
>
0
?
maxImagesCount
:
9
;
// Default is 9 / 默认最大可选9张图片
self
.
maxImagesCount
=
maxImagesCount
>
0
?
maxImagesCount
:
9
;
// Default is 9 / 默认最大可选9张图片
self
.
pickerDelegate
=
delegate
;
self
.
pickerDelegate
=
delegate
;
self
.
selectedModels
=
[
NSMutableArray
array
];
// Allow user picking original photo and video, you also can set No after this method
// Allow user picking original photo and video, you also can set No after this method
// 默认准许用户选择原图和视频, 你也可以在这个方法后置为NO
// 默认准许用户选择原图和视频, 你也可以在这个方法后置为NO
_
allowPickingOriginalPhoto
=
YES
;
self
.
allowPickingOriginalPhoto
=
YES
;
_
allowPickingVideo
=
YES
;
self
.
allowPickingVideo
=
YES
;
_
allowPickingImage
=
YES
;
self
.
allowPickingImage
=
YES
;
_
timeout
=
15
;
self
.
timeout
=
15
;
_
photoWidth
=
828
.
0
;
self
.
photoWidth
=
828
.
0
;
if
(
!
[[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
if
(
!
[[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
_tipLable
=
[[
UILabel
alloc
]
init
];
_tipLable
=
[[
UILabel
alloc
]
init
];
...
@@ -188,6 +190,30 @@
...
@@ -188,6 +190,30 @@
}
}
}
}
-
(
void
)
setSelectedAssets
:(
NSArray
*
)
selectedAssets
{
_selectedAssets
=
selectedAssets
;
_selectedModels
=
[
NSMutableArray
array
];
for
(
id
asset
in
selectedAssets
)
{
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypePhoto
];
model
.
isSelected
=
YES
;
[
_selectedModels
addObject
:
model
];
}
}
-
(
void
)
setAllowPickingImage
:(
BOOL
)
allowPickingImage
{
_allowPickingImage
=
allowPickingImage
;
NSString
*
allowPickingImageStr
=
_allowPickingImage
?
@"1"
:
@"0"
;
[[
NSUserDefaults
standardUserDefaults
]
setObject
:
allowPickingImageStr
forKey
:
@"tz_allowPickingImage"
];
[[
NSUserDefaults
standardUserDefaults
]
synchronize
];
}
-
(
void
)
setAllowPickingVideo
:(
BOOL
)
allowPickingVideo
{
_allowPickingVideo
=
allowPickingVideo
;
NSString
*
allowPickingVideoStr
=
_allowPickingVideo
?
@"1"
:
@"0"
;
[[
NSUserDefaults
standardUserDefaults
]
setObject
:
allowPickingVideoStr
forKey
:
@"tz_allowPickingVideo"
];
[[
NSUserDefaults
standardUserDefaults
]
synchronize
];
}
-
(
void
)
pushViewController
:(
UIViewController
*
)
viewController
animated
:(
BOOL
)
animated
{
-
(
void
)
pushViewController
:(
UIViewController
*
)
viewController
animated
:(
BOOL
)
animated
{
if
(
iOS7Later
)
viewController
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
iOS7Later
)
viewController
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
_timer
)
{
[
_timer
invalidate
];
_timer
=
nil
;}
if
(
_timer
)
{
[
_timer
invalidate
];
_timer
=
nil
;}
...
@@ -228,24 +254,36 @@
...
@@ -228,24 +254,36 @@
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
imagePickerVc
hideProgressHUD
];
[
imagePickerVc
hideProgressHUD
];
if
(
_albumArr
)
return
;
if
(
_albumArr
)
{
[
self
configTableView
];
for
(
TZAlbumModel
*
albumModel
in
_albumArr
)
{
albumModel
.
selectedModels
=
imagePickerVc
.
selectedModels
;
}
[
_tableView
reloadData
];
}
else
{
[
self
configTableView
];
}
}
}
-
(
void
)
configTableView
{
-
(
void
)
configTableView
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[[
TZImageManager
manager
]
getAllAlbums
:
imagePickerVc
.
allowPickingVideo
allowPickingImage
:
imagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAlbumModel
*>
*
models
)
{
[[
TZImageManager
manager
]
getAllAlbums
:
imagePickerVc
.
allowPickingVideo
allowPickingImage
:
imagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAlbumModel
*>
*
models
)
{
_albumArr
=
[
NSMutableArray
arrayWithArray
:
models
];
_albumArr
=
[
NSMutableArray
arrayWithArray
:
models
];
for
(
TZAlbumModel
*
albumModel
in
_albumArr
)
{
CGFloat
top
=
44
;
albumModel
.
selectedModels
=
imagePickerVc
.
selectedModels
;
if
(
iOS7Later
)
top
+=
20
;
}
_tableView
=
[[
UITableView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
top
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
top
)
style
:
UITableViewStylePlain
];
if
(
!
_tableView
)
{
_tableView
.
rowHeight
=
70
;
CGFloat
top
=
44
;
_tableView
.
tableFooterView
=
[[
UIView
alloc
]
init
];
if
(
iOS7Later
)
top
+=
20
;
_tableView
.
dataSource
=
self
;
_tableView
=
[[
UITableView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
top
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
top
)
style
:
UITableViewStylePlain
];
_tableView
.
delegate
=
self
;
_tableView
.
rowHeight
=
70
;
[
_tableView
registerClass
:[
TZAlbumCell
class
]
forCellReuseIdentifier
:
@"TZAlbumCell"
];
_tableView
.
tableFooterView
=
[[
UIView
alloc
]
init
];
[
self
.
view
addSubview
:
_tableView
];
_tableView
.
dataSource
=
self
;
_tableView
.
delegate
=
self
;
[
_tableView
registerClass
:[
TZAlbumCell
class
]
forCellReuseIdentifier
:
@"TZAlbumCell"
];
[
self
.
view
addSubview
:
_tableView
];
}
else
{
[
_tableView
reloadData
];
}
}];
}];
}
}
...
@@ -270,13 +308,20 @@
...
@@ -270,13 +308,20 @@
-
(
UITableViewCell
*
)
tableView
:(
UITableView
*
)
tableView
cellForRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
UITableViewCell
*
)
tableView
:(
UITableView
*
)
tableView
cellForRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
TZAlbumCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
@"TZAlbumCell"
];
TZAlbumCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
@"TZAlbumCell"
];
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
cell
.
selectedCountButton
.
backgroundColor
=
imagePickerVc
.
oKButtonTitleColorNormal
;
cell
.
model
=
_albumArr
[
indexPath
.
row
];
cell
.
model
=
_albumArr
[
indexPath
.
row
];
cell
.
accessoryType
=
UITableViewCellAccessoryDisclosureIndicator
;
return
cell
;
return
cell
;
}
}
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
TZPhotoPickerController
*
photoPickerVc
=
[[
TZPhotoPickerController
alloc
]
init
];
TZPhotoPickerController
*
photoPickerVc
=
[[
TZPhotoPickerController
alloc
]
init
];
photoPickerVc
.
model
=
_albumArr
[
indexPath
.
row
];
TZAlbumModel
*
model
=
_albumArr
[
indexPath
.
row
];
photoPickerVc
.
model
=
model
;
[
photoPickerVc
setBackButtonClickHandle
:
^
(
TZAlbumModel
*
model
)
{
[
_albumArr
replaceObjectAtIndex
:
indexPath
.
row
withObject
:
model
];
}];
[
self
.
navigationController
pushViewController
:
photoPickerVc
animated
:
YES
];
[
self
.
navigationController
pushViewController
:
photoPickerVc
animated
:
YES
];
[
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
NO
];
[
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
NO
];
}
}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.h
View file @
a567b512
...
@@ -12,5 +12,6 @@
...
@@ -12,5 +12,6 @@
@interface
TZPhotoPickerController
:
UIViewController
@interface
TZPhotoPickerController
:
UIViewController
@property
(
nonatomic
,
strong
)
TZAlbumModel
*
model
;
@property
(
nonatomic
,
strong
)
TZAlbumModel
*
model
;
@property
(
nonatomic
,
copy
)
void
(
^
backButtonClickHandle
)(
TZAlbumModel
*
model
);
@end
@end
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
a567b512
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#import "TZImageManager.h"
#import "TZImageManager.h"
#import "TZVideoPlayerController.h"
#import "TZVideoPlayerController.h"
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
>
{
@interface
TZPhotoPickerController
()
<
UICollectionViewDataSource
,
UICollectionViewDelegate
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
>
{
UICollectionView
*
_collectionView
;
UICollectionView
*
_collectionView
;
NSMutableArray
*
_photoArr
;
NSMutableArray
*
_photoArr
;
...
@@ -29,34 +29,72 @@
...
@@ -29,34 +29,72 @@
BOOL
_isSelectOriginalPhoto
;
BOOL
_isSelectOriginalPhoto
;
BOOL
_shouldScrollToBottom
;
BOOL
_shouldScrollToBottom
;
}
}
@property
(
nonatomic
,
strong
)
NSMutableArray
*
selectedPhotoArr
;
@property
CGRect
previousPreheatRect
;
@property
CGRect
previousPreheatRect
;
@property
(
nonatomic
,
strong
)
UIImagePickerController
*
imagePickerVc
;
@property
(
nonatomic
,
strong
)
TZImagePickerController
*
tzImagePickerVc
;
@end
@end
static
CGSize
AssetGridThumbnailSize
;
static
CGSize
AssetGridThumbnailSize
;
@implementation
TZPhotoPickerController
@implementation
TZPhotoPickerController
-
(
NSMutableArray
*
)
selectedPhotoArr
{
-
(
UIImagePickerController
*
)
imagePickerVc
{
if
(
_selectedPhotoArr
==
nil
)
_selectedPhotoArr
=
[
NSMutableArray
array
];
if
(
_imagePickerVc
==
nil
)
{
return
_selectedPhotoArr
;
_imagePickerVc
=
[[
UIImagePickerController
alloc
]
init
];
_imagePickerVc
.
delegate
=
self
;
_imagePickerVc
.
allowsEditing
=
YES
;
// set appearance / 改变相册选择页的导航栏外观
_imagePickerVc
.
navigationBar
.
barTintColor
=
self
.
navigationController
.
navigationBar
.
barTintColor
;
_imagePickerVc
.
navigationBar
.
tintColor
=
self
.
navigationController
.
navigationBar
.
tintColor
;
UIBarButtonItem
*
tzBarItem
,
*
BarItem
;
if
(
iOS8Later
)
{
tzBarItem
=
[
UIBarButtonItem
appearanceWhenContainedIn
:[
TZImagePickerController
class
],
nil
];
BarItem
=
[
UIBarButtonItem
appearanceWhenContainedIn
:[
UIImagePickerController
class
],
nil
];
}
else
{
tzBarItem
=
[
UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses
:@[[
TZImagePickerController
class
]]];
BarItem
=
[
UIBarButtonItem
appearanceWhenContainedInInstancesOfClasses
:@[[
UIImagePickerController
class
]]];
}
NSDictionary
*
titleTextAttributes
=
[
tzBarItem
titleTextAttributesForState
:
UIControlStateNormal
];
[
BarItem
setTitleTextAttributes
:
titleTextAttributes
forState
:
UIControlStateNormal
];
}
return
_imagePickerVc
;
}
}
-
(
void
)
viewDidLoad
{
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
[
super
viewDidLoad
];
__weak
typeof
(
self
)
weakSelf
=
self
;
_tzImagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
_isSelectOriginalPhoto
=
_tzImagePickerVc
.
isSelectOriginalPhoto
;
_shouldScrollToBottom
=
YES
;
_shouldScrollToBottom
=
YES
;
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
navigationItem
.
title
=
_model
.
name
;
self
.
navigationItem
.
title
=
_model
.
name
;
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
)];
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
])
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
imagePickerVc
.
allowPickingVideo
allowPickingImage
:
imagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
_tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
_tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
_photoArr
=
[
NSMutableArray
arrayWithArray
:
models
];
_photoArr
=
[
NSMutableArray
arrayWithArray
:
models
];
[
self
configCollectionView
];
[
self
initSubviews
];
[
self
configBottomToolBar
];
}];
}];
}
else
{
_photoArr
=
[
NSMutableArray
arrayWithArray
:
_model
.
models
];
[
self
initSubviews
];
}
// [self resetCachedAssets];
// [self resetCachedAssets];
}
}
-
(
void
)
initSubviews
{
[
self
checkSelectedModels
];
[
self
configCollectionView
];
[
self
configBottomToolBar
];
}
-
(
void
)
viewWillDisappear
:(
BOOL
)
animated
{
[
super
viewWillDisappear
:
animated
];
_tzImagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
if
(
self
.
backButtonClickHandle
)
{
self
.
backButtonClickHandle
(
_model
);
}
}
-
(
void
)
configCollectionView
{
-
(
void
)
configCollectionView
{
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
CGFloat
margin
=
4
;
CGFloat
margin
=
4
;
...
@@ -73,17 +111,19 @@ static CGSize AssetGridThumbnailSize;
...
@@ -73,17 +111,19 @@ static CGSize AssetGridThumbnailSize;
_collectionView
.
alwaysBounceHorizontal
=
NO
;
_collectionView
.
alwaysBounceHorizontal
=
NO
;
if
(
iOS7Later
)
_collectionView
.
contentInset
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
2
);
if
(
iOS7Later
)
_collectionView
.
contentInset
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
2
);
_collectionView
.
scrollIndicatorInsets
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
-
2
);
_collectionView
.
scrollIndicatorInsets
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
-
2
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
3
)
/
4
)
*
self
.
view
.
tz_width
);
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
)
{
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
4
)
/
4
)
*
self
.
view
.
tz_width
);
}
else
{
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
3
)
/
4
)
*
self
.
view
.
tz_width
);
}
[
self
.
view
addSubview
:
_collectionView
];
[
self
.
view
addSubview
:
_collectionView
];
[
_collectionView
registerClass
:[
TZAssetCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCell"
];
[
_collectionView
registerClass
:[
TZAssetCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCell"
];
[
_collectionView
registerClass
:[
TZAssetCameraCell
class
]
forCellWithReuseIdentifier
:
@"TZAssetCameraCell"
];
}
}
-
(
void
)
viewWillAppear
:(
BOOL
)
animated
{
-
(
void
)
viewWillAppear
:(
BOOL
)
animated
{
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
if
(
_shouldScrollToBottom
&&
_photoArr
.
count
>
0
)
{
[
self
scrollCollectionViewToBottom
];
[
_collectionView
scrollToItemAtIndexPath
:[
NSIndexPath
indexPathForItem
:(
_photoArr
.
count
-
1
)
inSection
:
0
]
atScrollPosition
:
UICollectionViewScrollPositionBottom
animated
:
NO
];
_shouldScrollToBottom
=
NO
;
}
// Determine the size of the thumbnails to request from the PHCachingImageManager
// Determine the size of the thumbnails to request from the PHCachingImageManager
CGFloat
scale
=
[
UIScreen
mainScreen
].
scale
;
CGFloat
scale
=
[
UIScreen
mainScreen
].
scale
;
CGSize
cellSize
=
((
UICollectionViewFlowLayout
*
)
_collectionView
.
collectionViewLayout
).
itemSize
;
CGSize
cellSize
=
((
UICollectionViewFlowLayout
*
)
_collectionView
.
collectionViewLayout
).
itemSize
;
...
@@ -110,10 +150,9 @@ static CGSize AssetGridThumbnailSize;
...
@@ -110,10 +150,9 @@ static CGSize AssetGridThumbnailSize;
[
_previewButton
setTitle
:
@"预览"
forState
:
UIControlStateDisabled
];
[
_previewButton
setTitle
:
@"预览"
forState
:
UIControlStateDisabled
];
[
_previewButton
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateNormal
];
[
_previewButton
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateNormal
];
[
_previewButton
setTitleColor
:[
UIColor
lightGrayColor
]
forState
:
UIControlStateDisabled
];
[
_previewButton
setTitleColor
:[
UIColor
lightGrayColor
]
forState
:
UIControlStateDisabled
];
_previewButton
.
enabled
=
NO
;
_previewButton
.
enabled
=
_tzImagePickerVc
.
selectedModels
.
count
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
if
(
imagePickerVc
.
allowPickingOriginalPhoto
)
{
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
.
frame
=
CGRectMake
(
50
,
self
.
view
.
tz_height
-
50
,
130
,
50
);
_originalPhotoButton
.
frame
=
CGRectMake
(
50
,
self
.
view
.
tz_height
-
50
,
130
,
50
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
-
8
,
0
,
0
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
-
8
,
0
,
0
);
...
@@ -126,7 +165,8 @@ static CGSize AssetGridThumbnailSize;
...
@@ -126,7 +165,8 @@ static CGSize AssetGridThumbnailSize;
[
_originalPhotoButton
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_original_def.png"
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_original_def.png"
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_original_sel.png"
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_original_sel.png"
]
forState
:
UIControlStateSelected
];
_originalPhotoButton
.
enabled
=
_selectedPhotoArr
.
count
>
0
;
_originalPhotoButton
.
selected
=
_isSelectOriginalPhoto
;
_originalPhotoButton
.
enabled
=
_tzImagePickerVc
.
selectedModels
.
count
>
0
;
_originalPhotoLable
=
[[
UILabel
alloc
]
init
];
_originalPhotoLable
=
[[
UILabel
alloc
]
init
];
_originalPhotoLable
.
frame
=
CGRectMake
(
70
,
0
,
60
,
50
);
_originalPhotoLable
.
frame
=
CGRectMake
(
70
,
0
,
60
,
50
);
...
@@ -142,13 +182,13 @@ static CGSize AssetGridThumbnailSize;
...
@@ -142,13 +182,13 @@ static CGSize AssetGridThumbnailSize;
[
_okButton
addTarget
:
self
action
:
@selector
(
okButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_okButton
addTarget
:
self
action
:
@selector
(
okButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateNormal
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateNormal
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateDisabled
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateDisabled
];
[
_okButton
setTitleColor
:
i
magePickerVc
.
oKButtonTitleColorNormal
forState
:
UIControlStateNormal
];
[
_okButton
setTitleColor
:
_tzI
magePickerVc
.
oKButtonTitleColorNormal
forState
:
UIControlStateNormal
];
[
_okButton
setTitleColor
:
i
magePickerVc
.
oKButtonTitleColorDisabled
forState
:
UIControlStateDisabled
];
[
_okButton
setTitleColor
:
_tzI
magePickerVc
.
oKButtonTitleColorDisabled
forState
:
UIControlStateDisabled
];
_okButton
.
enabled
=
NO
;
_okButton
.
enabled
=
_tzImagePickerVc
.
selectedModels
.
count
;
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_number_icon.png"
]];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_number_icon.png"
]];
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
12
,
26
,
26
);
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
12
,
26
,
26
);
_numberImageView
.
hidden
=
_
selectedPhotoArr
.
count
<=
0
;
_numberImageView
.
hidden
=
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberLable
=
[[
UILabel
alloc
]
init
];
_numberLable
=
[[
UILabel
alloc
]
init
];
...
@@ -156,8 +196,8 @@ static CGSize AssetGridThumbnailSize;
...
@@ -156,8 +196,8 @@ static CGSize AssetGridThumbnailSize;
_numberLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_numberLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
selectedPhotoArr
.
count
];
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
tzImagePickerVc
.
selectedModels
.
count
];
_numberLable
.
hidden
=
_
selectedPhotoArr
.
count
<=
0
;
_numberLable
.
hidden
=
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
UIView
*
divide
=
[[
UIView
alloc
]
init
];
UIView
*
divide
=
[[
UIView
alloc
]
init
];
...
@@ -190,7 +230,7 @@ static CGSize AssetGridThumbnailSize;
...
@@ -190,7 +230,7 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
previewButtonClick
{
-
(
void
)
previewButtonClick
{
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
photoPreviewVc
.
photoArr
=
[
NSArray
arrayWithArray
:
self
.
selectedPhotoArr
];
photoPreviewVc
.
photoArr
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedModels
];
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
}
}
...
@@ -202,40 +242,39 @@ static CGSize AssetGridThumbnailSize;
...
@@ -202,40 +242,39 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
okButtonClick
{
-
(
void
)
okButtonClick
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
_tzImagePickerVc
showProgressHUD
];
[
imagePickerVc
showProgressHUD
];
NSMutableArray
*
photos
=
[
NSMutableArray
array
];
NSMutableArray
*
photos
=
[
NSMutableArray
array
];
NSMutableArray
*
assets
=
[
NSMutableArray
array
];
NSMutableArray
*
assets
=
[
NSMutableArray
array
];
NSMutableArray
*
infoArr
=
[
NSMutableArray
array
];
NSMutableArray
*
infoArr
=
[
NSMutableArray
array
];
for
(
NSInteger
i
=
0
;
i
<
_
selectedPhotoArr
.
count
;
i
++
)
{
[
photos
addObject
:
@1
];[
assets
addObject
:
@1
];[
infoArr
addObject
:
@1
];
}
for
(
NSInteger
i
=
0
;
i
<
_
tzImagePickerVc
.
selectedModels
.
count
;
i
++
)
{
[
photos
addObject
:
@1
];[
assets
addObject
:
@1
];[
infoArr
addObject
:
@1
];
}
//
[TZImageManager manager].shouldFixOrientation = YES;
[
TZImageManager
manager
].
shouldFixOrientation
=
YES
;
for
(
NSInteger
i
=
0
;
i
<
_
selectedPhotoArr
.
count
;
i
++
)
{
for
(
NSInteger
i
=
0
;
i
<
_
tzImagePickerVc
.
selectedModels
.
count
;
i
++
)
{
TZAssetModel
*
model
=
_
selectedPhotoArr
[
i
];
TZAssetModel
*
model
=
_
tzImagePickerVc
.
selectedModels
[
i
];
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
isDegraded
)
return
;
if
(
isDegraded
)
return
;
if
(
photo
)
{
if
(
photo
)
{
photo
=
[
self
scaleImage
:
photo
toSize
:
CGSizeMake
(
imagePickerVc
.
photoWidth
,
i
magePickerVc
.
photoWidth
*
photo
.
size
.
height
/
photo
.
size
.
width
)];
photo
=
[
self
scaleImage
:
photo
toSize
:
CGSizeMake
(
_tzImagePickerVc
.
photoWidth
,
_tzI
magePickerVc
.
photoWidth
*
photo
.
size
.
height
/
photo
.
size
.
width
)];
[
photos
replaceObjectAtIndex
:
i
withObject
:
photo
];
[
photos
replaceObjectAtIndex
:
i
withObject
:
photo
];
}
}
if
(
info
)
[
infoArr
replaceObjectAtIndex
:
i
withObject
:
info
];
if
(
info
)
[
infoArr
replaceObjectAtIndex
:
i
withObject
:
info
];
if
(
_isSelectOriginalPhoto
)
[
assets
replaceObjectAtIndex
:
i
withObject
:
model
.
asset
];
[
assets
replaceObjectAtIndex
:
i
withObject
:
model
.
asset
];
for
(
id
item
in
photos
)
{
if
([
item
isKindOfClass
:[
NSNumber
class
]])
return
;
}
for
(
id
item
in
photos
)
{
if
([
item
isKindOfClass
:[
NSNumber
class
]])
return
;
}
if
([
imagePickerVc
.
pickerDelegate
respondsToSelector
:
@selector
(
imagePickerController
:
didFinishPickingPhotos
:
sourceAssets
:
)])
{
if
([
_tzImagePickerVc
.
pickerDelegate
respondsToSelector
:
@selector
(
imagePickerController
:
didFinishPickingPhotos
:
sourceAssets
:
isSelectOriginalPhoto
:
)])
{
[
imagePickerVc
.
pickerDelegate
imagePickerController
:
imagePickerVc
didFinishPickingPhotos
:
photos
sourceAssets
:
assets
];
[
_tzImagePickerVc
.
pickerDelegate
imagePickerController
:
_tzImagePickerVc
didFinishPickingPhotos
:
photos
sourceAssets
:
assets
isSelectOriginalPhoto
:
_isSelectOriginalPhoto
];
}
}
if
([
imagePickerVc
.
pickerDelegate
respondsToSelector
:
@selector
(
imagePickerController
:
didFinishPickingPhotos
:
sourceAssets
:
infos
:
)])
{
if
([
_tzImagePickerVc
.
pickerDelegate
respondsToSelector
:
@selector
(
imagePickerController
:
didFinishPickingPhotos
:
sourceAssets
:
isSelectOriginalPhoto
:
infos
:
)])
{
[
imagePickerVc
.
pickerDelegate
imagePickerController
:
imagePickerVc
didFinishPickingPhotos
:
photos
sourceAssets
:
assets
infos
:
infoArr
];
[
_tzImagePickerVc
.
pickerDelegate
imagePickerController
:
_tzImagePickerVc
didFinishPickingPhotos
:
photos
sourceAssets
:
assets
isSelectOriginalPhoto
:
_isSelectOriginalPhoto
infos
:
infoArr
];
}
}
if
(
i
magePickerVc
.
didFinishPickingPhotosHandle
)
{
if
(
_tzI
magePickerVc
.
didFinishPickingPhotosHandle
)
{
imagePickerVc
.
didFinishPickingPhotosHandle
(
photos
,
assets
);
_tzImagePickerVc
.
didFinishPickingPhotosHandle
(
photos
,
assets
,
_isSelectOriginalPhoto
);
}
}
if
(
i
magePickerVc
.
didFinishPickingPhotosWithInfosHandle
)
{
if
(
_tzI
magePickerVc
.
didFinishPickingPhotosWithInfosHandle
)
{
imagePickerVc
.
didFinishPickingPhotosWithInfosHandle
(
photos
,
assets
,
infoArr
);
_tzImagePickerVc
.
didFinishPickingPhotosWithInfosHandle
(
photos
,
assets
,
_isSelectOriginalPhoto
,
infoArr
);
}
}
[
i
magePickerVc
hideProgressHUD
];
[
_tzI
magePickerVc
hideProgressHUD
];
[
self
.
navigationController
dismissViewControllerAnimated
:
YES
completion
:
nil
];
[
self
.
navigationController
dismissViewControllerAnimated
:
YES
completion
:
nil
];
}];
}];
}
}
...
@@ -244,10 +283,22 @@ static CGSize AssetGridThumbnailSize;
...
@@ -244,10 +283,22 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - UICollectionViewDataSource && Delegate
#pragma mark - UICollectionViewDataSource && Delegate
-
(
NSInteger
)
collectionView
:(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:(
NSInteger
)
section
{
-
(
NSInteger
)
collectionView
:(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:(
NSInteger
)
section
{
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
])
{
if
(
_tzImagePickerVc
.
allowPickingImage
)
{
return
_photoArr
.
count
+
1
;
}
}
return
_photoArr
.
count
;
return
_photoArr
.
count
;
}
}
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// the cell lead to take a picture / 去拍照的cell
if
(
indexPath
.
row
>=
_photoArr
.
count
)
{
TZAssetCameraCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCameraCell"
forIndexPath
:
indexPath
];
cell
.
imageView
.
image
=
[
UIImage
imageNamedFromMyBundle
:
@"takePicture.png"
];
return
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
=
_photoArr
[
indexPath
.
row
];
cell
.
model
=
model
;
cell
.
model
=
model
;
...
@@ -260,18 +311,22 @@ static CGSize AssetGridThumbnailSize;
...
@@ -260,18 +311,22 @@ static CGSize AssetGridThumbnailSize;
if
(
isSelected
)
{
if
(
isSelected
)
{
weakCell
.
selectPhotoButton
.
selected
=
NO
;
weakCell
.
selectPhotoButton
.
selected
=
NO
;
model
.
isSelected
=
NO
;
model
.
isSelected
=
NO
;
[
weakSelf
.
selectedPhotoArr
removeObject
:
model
];
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
weakSelf
.
tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([
model
.
asset
isEqual
:
model_item
.
asset
])
{
[
weakSelf
.
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
}
}
[
weakSelf
refreshBottomToolBarStatus
];
[
weakSelf
refreshBottomToolBarStatus
];
}
else
{
}
else
{
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
if
(
weakSelf
.
tzImagePickerVc
.
selectedModels
.
count
<
weakSelf
.
tzImagePickerVc
.
maxImagesCount
)
{
if
(
weakSelf
.
selectedPhotoArr
.
count
<
imagePickerVc
.
maxImagesCount
)
{
weakCell
.
selectPhotoButton
.
selected
=
YES
;
weakCell
.
selectPhotoButton
.
selected
=
YES
;
model
.
isSelected
=
YES
;
model
.
isSelected
=
YES
;
[
weakSelf
.
selectedPhotoArr
addObject
:
model
];
[
weakSelf
.
tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
weakSelf
refreshBottomToolBarStatus
];
[
weakSelf
refreshBottomToolBarStatus
];
}
else
{
}
else
{
[
imagePickerVc
showAlertWithTitle
:[
NSString
stringWithFormat
:
@"你最多只能选择%zd张照片"
,
i
magePickerVc
.
maxImagesCount
]];
[
weakSelf
.
tzImagePickerVc
showAlertWithTitle
:[
NSString
stringWithFormat
:
@"你最多只能选择%zd张照片"
,
weakSelf
.
tzI
magePickerVc
.
maxImagesCount
]];
}
}
}
}
[
UIView
showOscillatoryAnimationWithLayer
:
weakLayer
type
:
TZOscillatoryAnimationToSmaller
];
[
UIView
showOscillatoryAnimationWithLayer
:
weakLayer
type
:
TZOscillatoryAnimationToSmaller
];
...
@@ -280,9 +335,14 @@ static CGSize AssetGridThumbnailSize;
...
@@ -280,9 +335,14 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// take a picture / 去拍照
if
(
indexPath
.
row
>=
_photoArr
.
count
)
{
[
self
takePicture
];
return
;
}
// preview phote or video / 预览照片或视频
TZAssetModel
*
model
=
_photoArr
[
indexPath
.
row
];
TZAssetModel
*
model
=
_photoArr
[
indexPath
.
row
];
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
_
selectedPhotoArr
.
count
>
0
)
{
if
(
_
tzImagePickerVc
.
selectedModels
.
count
>
0
)
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
imagePickerVc
showAlertWithTitle
:
@"选择照片时不能选择视频"
];
[
imagePickerVc
showAlertWithTitle
:
@"选择照片时不能选择视频"
];
}
else
{
}
else
{
...
@@ -308,15 +368,30 @@ static CGSize AssetGridThumbnailSize;
...
@@ -308,15 +368,30 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - Private Method
#pragma mark - Private Method
-
(
void
)
takePicture
{
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
self
.
imagePickerVc
.
sourceType
=
sourceType
;
if
(
iOS8Later
)
{
_imagePickerVc
.
modalPresentationStyle
=
UIModalPresentationOverCurrentContext
;
}
[
self
presentViewController
:
_imagePickerVc
animated
:
YES
completion
:
nil
];
}
else
{
NSLog
(
@"模拟器中无法打开照相机,请在真机中使用"
);
}
}
-
(
void
)
refreshBottomToolBarStatus
{
-
(
void
)
refreshBottomToolBarStatus
{
_previewButton
.
enabled
=
self
.
selectedPhotoArr
.
count
>
0
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
_okButton
.
enabled
=
self
.
selectedPhotoArr
.
count
>
0
;
_previewButton
.
enabled
=
imagePickerVc
.
selectedModels
.
count
>
0
;
_okButton
.
enabled
=
imagePickerVc
.
selectedModels
.
count
>
0
;
_numberImageView
.
hidden
=
_selectedPhotoArr
.
count
<=
0
;
_numberImageView
.
hidden
=
imagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
hidden
=
_selectedPhotoArr
.
count
<=
0
;
_numberLable
.
hidden
=
imagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_selectedPhotoArr
.
count
];
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
imagePickerVc
.
selectedModels
.
count
];
_originalPhotoButton
.
enabled
=
_selectedPhotoArr
.
count
>
0
;
_originalPhotoButton
.
enabled
=
imagePickerVc
.
selectedModels
.
count
>
0
;
_originalPhotoButton
.
selected
=
(
_isSelectOriginalPhoto
&&
_originalPhotoButton
.
enabled
);
_originalPhotoButton
.
selected
=
(
_isSelectOriginalPhoto
&&
_originalPhotoButton
.
enabled
);
_originalPhotoLable
.
hidden
=
(
!
_originalPhotoButton
.
isSelected
);
_originalPhotoLable
.
hidden
=
(
!
_originalPhotoButton
.
isSelected
);
if
(
_isSelectOriginalPhoto
)
[
self
getSelectedPhotoBytes
];
if
(
_isSelectOriginalPhoto
)
[
self
getSelectedPhotoBytes
];
...
@@ -324,15 +399,13 @@ static CGSize AssetGridThumbnailSize;
...
@@ -324,15 +399,13 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
pushPhotoPrevireViewController
:(
TZPhotoPreviewController
*
)
photoPreviewVc
{
-
(
void
)
pushPhotoPrevireViewController
:(
TZPhotoPreviewController
*
)
photoPreviewVc
{
photoPreviewVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
photoPreviewVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
photoPreviewVc
.
selectedPhotoArr
=
self
.
selectedPhotoArr
;
photoPreviewVc
.
backButtonClickBlock
=
^
(
BOOL
isSelectOriginalPhoto
)
{
photoPreviewVc
.
returnNewSelectedPhotoArrBlock
=
^
(
NSMutableArray
*
newSelectedPhotoArr
,
BOOL
isSelectOriginalPhoto
)
{
_selectedPhotoArr
=
newSelectedPhotoArr
;
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
self
checkSelectedModels
];
[
_collectionView
reloadData
];
[
_collectionView
reloadData
];
[
self
refreshBottomToolBarStatus
];
[
self
refreshBottomToolBarStatus
];
};
};
photoPreviewVc
.
okButtonClickBlock
=
^
(
NSMutableArray
*
newSelectedPhotoArr
,
BOOL
isSelectOriginalPhoto
){
photoPreviewVc
.
okButtonClickBlock
=
^
(
BOOL
isSelectOriginalPhoto
){
_selectedPhotoArr
=
newSelectedPhotoArr
;
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
_isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
self
okButtonClick
];
[
self
okButtonClick
];
};
};
...
@@ -340,7 +413,8 @@ static CGSize AssetGridThumbnailSize;
...
@@ -340,7 +413,8 @@ static CGSize AssetGridThumbnailSize;
}
}
-
(
void
)
getSelectedPhotoBytes
{
-
(
void
)
getSelectedPhotoBytes
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:
_selectedPhotoArr
completion
:
^
(
NSString
*
totalBytes
)
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:
imagePickerVc
.
selectedModels
completion
:
^
(
NSString
*
totalBytes
)
{
_originalPhotoLable
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
_originalPhotoLable
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
}];
}];
}
}
...
@@ -354,6 +428,75 @@ static CGSize AssetGridThumbnailSize;
...
@@ -354,6 +428,75 @@ static CGSize AssetGridThumbnailSize;
return
newImage
;
return
newImage
;
}
}
-
(
void
)
scrollCollectionViewToBottom
{
if
(
_shouldScrollToBottom
&&
_photoArr
.
count
>
0
)
{
NSInteger
item
=
_photoArr
.
count
-
1
;
if
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
])
{
if
(
_tzImagePickerVc
.
allowPickingImage
)
{
item
+=
1
;
}
}
[
_collectionView
scrollToItemAtIndexPath
:[
NSIndexPath
indexPathForItem
:
item
inSection
:
0
]
atScrollPosition
:
UICollectionViewScrollPositionBottom
animated
:
NO
];
_shouldScrollToBottom
=
NO
;
}
}
-
(
void
)
checkSelectedModels
{
for
(
TZAssetModel
*
model
in
_photoArr
)
{
model
.
isSelected
=
NO
;
NSMutableArray
*
selectedAssets
=
[
NSMutableArray
array
];
for
(
TZAssetModel
*
model
in
_tzImagePickerVc
.
selectedModels
)
{
[
selectedAssets
addObject
:
model
.
asset
];
}
if
([
selectedAssets
containsObject
:
model
.
asset
])
{
model
.
isSelected
=
YES
;
}
}
}
#pragma mark - UIImagePickerControllerDelegate
-
(
void
)
imagePickerController
:(
UIImagePickerController
*
)
picker
didFinishPickingMediaWithInfo
:(
NSDictionary
*
)
info
{
[
picker
dismissViewControllerAnimated
:
YES
completion
:
nil
];
NSString
*
type
=
[
info
objectForKey
:
UIImagePickerControllerMediaType
];
if
([
type
isEqualToString
:
@"public.image"
])
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
imagePickerVc
showProgressHUD
];
UIImage
*
image
=
[
info
objectForKey
:
UIImagePickerControllerEditedImage
];
UIImageWriteToSavedPhotosAlbum
(
image
,
self
,
@selector
(
image
:
didFinishSavingWithError
:
contextInfo
:
),
nil
);
}
}
-
(
void
)
image
:(
UIImage
*
)
image
didFinishSavingWithError
:(
NSError
*
)
error
contextInfo
:(
void
*
)
contextInfo
{
if
(
error
)
{
[
_tzImagePickerVc
hideProgressHUD
];
[
_tzImagePickerVc
showAlertWithTitle
:
error
.
localizedDescription
];
}
else
{
[[
TZImageManager
manager
]
getCameraRollAlbum
:
_tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
_tzImagePickerVc
.
allowPickingImage
completion
:^
(
TZAlbumModel
*
model
)
{
_model
=
model
;
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
_tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
_tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[
_tzImagePickerVc
hideProgressHUD
];
TZAssetModel
*
model
=
[
models
lastObject
];
[
_photoArr
addObject
:
model
];
if
(
_tzImagePickerVc
.
selectedModels
.
count
<
_tzImagePickerVc
.
maxImagesCount
)
{
model
.
isSelected
=
YES
;
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
self
refreshBottomToolBarStatus
];
}
[
_collectionView
reloadData
];
_shouldScrollToBottom
=
YES
;
[
self
scrollCollectionViewToBottom
];
}];
}];
}
}
-
(
void
)
imagePickerControllerDidCancel
:(
UIImagePickerController
*
)
picker
{
[
picker
dismissViewControllerAnimated
:
YES
completion
:
nil
];
}
#pragma mark - Asset Caching
#pragma mark - Asset Caching
-
(
void
)
resetCachedAssets
{
-
(
void
)
resetCachedAssets
{
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.h
View file @
a567b512
...
@@ -11,12 +11,12 @@
...
@@ -11,12 +11,12 @@
@interface
TZPhotoPreviewController
:
UIViewController
@interface
TZPhotoPreviewController
:
UIViewController
@property
(
nonatomic
,
strong
)
NSArray
*
photoArr
;
///< All photos / 所有图片的数组
@property
(
nonatomic
,
strong
)
NSArray
*
photoArr
;
///< All photos / 所有图片的数组
@property
(
nonatomic
,
strong
)
NSMutableArray
*
selectedPhotoArr
;
///< Current selected photos / 当前选中的图片数组
//
@property (nonatomic, strong) NSMutableArray *selectedPhotoArr; ///< Current selected 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
(
^
returnNewSelectedPhotoArrBlock
)(
NSMutableArray
*
newSeletedPhotoArr
,
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
backButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
okButtonClickBlock
)(
NSMutableArray
*
newSeletedPhotoArr
,
BOOL
isSelectOriginalPhoto
);
@property
(
nonatomic
,
copy
)
void
(
^
okButtonClickBlock
)(
BOOL
isSelectOriginalPhoto
);
@end
@end
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
View file @
a567b512
...
@@ -28,18 +28,15 @@
...
@@ -28,18 +28,15 @@
UIButton
*
_originalPhotoButton
;
UIButton
*
_originalPhotoButton
;
UILabel
*
_originalPhotoLable
;
UILabel
*
_originalPhotoLable
;
}
}
@property
(
nonatomic
,
strong
)
TZImagePickerController
*
tzImagePickerVc
;
@end
@end
@implementation
TZPhotoPreviewController
@implementation
TZPhotoPreviewController
-
(
NSMutableArray
*
)
selectedPhotoArr
{
if
(
_selectedPhotoArr
==
nil
)
_selectedPhotoArr
=
[[
NSMutableArray
alloc
]
init
];
return
_selectedPhotoArr
;
}
-
(
void
)
viewDidLoad
{
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
[
super
viewDidLoad
];
__weak
typeof
(
self
)
weakSelf
=
self
;
_tzImagePickerVc
=
(
TZImagePickerController
*
)
weakSelf
.
navigationController
;
[
self
configCollectionView
];
[
self
configCollectionView
];
[
self
configCustomNaviBar
];
[
self
configCustomNaviBar
];
[
self
configBottomToolBar
];
[
self
configBottomToolBar
];
...
@@ -85,8 +82,7 @@
...
@@ -85,8 +82,7 @@
_toolBar
.
backgroundColor
=
[
UIColor
colorWithRed
:
rgb
green
:
rgb
blue
:
rgb
alpha
:
1
.
0
];
_toolBar
.
backgroundColor
=
[
UIColor
colorWithRed
:
rgb
green
:
rgb
blue
:
rgb
alpha
:
1
.
0
];
_toolBar
.
alpha
=
0
.
7
;
_toolBar
.
alpha
=
0
.
7
;
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
allowPickingOriginalPhoto
)
{
if
(
imagePickerVc
.
allowPickingOriginalPhoto
)
{
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_originalPhotoButton
.
frame
=
CGRectMake
(
5
,
0
,
120
,
44
);
_originalPhotoButton
.
frame
=
CGRectMake
(
5
,
0
,
120
,
44
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
-
8
,
0
,
0
);
_originalPhotoButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
0
,
-
8
,
0
,
0
);
...
@@ -115,20 +111,20 @@
...
@@ -115,20 +111,20 @@
_okButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_okButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
[
_okButton
addTarget
:
self
action
:
@selector
(
okButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_okButton
addTarget
:
self
action
:
@selector
(
okButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateNormal
];
[
_okButton
setTitle
:
@"确定"
forState
:
UIControlStateNormal
];
[
_okButton
setTitleColor
:
i
magePickerVc
.
oKButtonTitleColorNormal
forState
:
UIControlStateNormal
];
[
_okButton
setTitleColor
:
_tzI
magePickerVc
.
oKButtonTitleColorNormal
forState
:
UIControlStateNormal
];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_number_icon.png"
]];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
@"photo_number_icon.png"
]];
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
9
,
26
,
26
);
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
9
,
26
,
26
);
_numberImageView
.
hidden
=
_
selectedPhotoArr
.
count
<=
0
;
_numberImageView
.
hidden
=
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
=
[[
UILabel
alloc
]
init
];
_numberLable
=
[[
UILabel
alloc
]
init
];
_numberLable
.
frame
=
_numberImageView
.
frame
;
_numberLable
.
frame
=
_numberImageView
.
frame
;
_numberLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_numberLable
.
font
=
[
UIFont
systemFontOfSize
:
16
];
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
selectedPhotoArr
.
count
];
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
tzImagePickerVc
.
selectedModels
.
count
];
_numberLable
.
hidden
=
_
selectedPhotoArr
.
count
<=
0
;
_numberLable
.
hidden
=
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
[
_originalPhotoButton
addSubview
:
_originalPhotoLable
];
[
_originalPhotoButton
addSubview
:
_originalPhotoLable
];
...
@@ -164,20 +160,23 @@
...
@@ -164,20 +160,23 @@
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
if
(
!
selectButton
.
isSelected
)
{
if
(
!
selectButton
.
isSelected
)
{
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_tzImagePickerVc
.
selectedModels
.
count
>=
_tzImagePickerVc
.
maxImagesCount
)
{
if
(
self
.
selectedPhotoArr
.
count
>=
imagePickerVc
.
maxImagesCount
)
{
[
_tzImagePickerVc
showAlertWithTitle
:[
NSString
stringWithFormat
:
@"你最多只能选择%zd张照片"
,
_tzImagePickerVc
.
maxImagesCount
]];
[
imagePickerVc
showAlertWithTitle
:[
NSString
stringWithFormat
:
@"你最多只能选择%zd张照片"
,
imagePickerVc
.
maxImagesCount
]];
return
;
return
;
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制
}
else
{
}
else
{
[
self
.
selectedPhotoArr
addObject
:
model
];
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
[
_tzImagePickerVc
showAlertWithTitle
:
@"多选状态下选择视频,默认将视频当图片发送"
];
[
imagePickerVc
showAlertWithTitle
:
@"多选状态下选择视频,默认将视频当图片发送"
];
}
}
}
}
}
else
{
}
else
{
[
self
.
selectedPhotoArr
removeObject
:
model
];
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
self
.
tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([
model
.
asset
isEqual
:
model_item
.
asset
])
{
[
self
.
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
}
}
}
}
model
.
isSelected
=
!
selectButton
.
isSelected
;
model
.
isSelected
=
!
selectButton
.
isSelected
;
[
self
refreshNaviBarAndBottomBarState
];
[
self
refreshNaviBarAndBottomBarState
];
...
@@ -189,18 +188,18 @@
...
@@ -189,18 +188,18 @@
-
(
void
)
back
{
-
(
void
)
back
{
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
if
(
self
.
returnNewSelectedPhotoArr
Block
)
{
if
(
self
.
backButtonClick
Block
)
{
self
.
returnNewSelectedPhotoArrBlock
(
self
.
selectedPhotoArr
,
_isSelectOriginalPhoto
);
self
.
backButtonClickBlock
(
_isSelectOriginalPhoto
);
}
}
}
}
-
(
void
)
okButtonClick
{
-
(
void
)
okButtonClick
{
if
(
_
selectedPhotoArr
.
count
==
0
)
{
if
(
_
tzImagePickerVc
.
selectedModels
.
count
==
0
)
{
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
[
_
selectedPhotoArr
addObject
:
model
];
[
_
tzImagePickerVc
.
selectedModels
addObject
:
model
];
}
}
if
(
self
.
okButtonClickBlock
)
{
if
(
self
.
okButtonClickBlock
)
{
self
.
okButtonClickBlock
(
self
.
selectedPhotoArr
,
_isSelectOriginalPhoto
);
self
.
okButtonClickBlock
(
_isSelectOriginalPhoto
);
}
}
}
}
...
@@ -218,10 +217,7 @@
...
@@ -218,10 +217,7 @@
-
(
void
)
scrollViewDidScroll
:(
UIScrollView
*
)
scrollView
{
-
(
void
)
scrollViewDidScroll
:(
UIScrollView
*
)
scrollView
{
CGPoint
offSet
=
scrollView
.
contentOffset
;
CGPoint
offSet
=
scrollView
.
contentOffset
;
_currentIndex
=
offSet
.
x
/
self
.
view
.
tz_width
;
_currentIndex
=
(
offSet
.
x
+
(
self
.
view
.
tz_width
*
0
.
5
))
/
self
.
view
.
tz_width
;
}
-
(
void
)
scrollViewDidEndDecelerating
:(
UIScrollView
*
)
scrollView
{
[
self
refreshNaviBarAndBottomBarState
];
[
self
refreshNaviBarAndBottomBarState
];
}
}
...
@@ -254,9 +250,9 @@
...
@@ -254,9 +250,9 @@
-
(
void
)
refreshNaviBarAndBottomBarState
{
-
(
void
)
refreshNaviBarAndBottomBarState
{
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
TZAssetModel
*
model
=
_photoArr
[
_currentIndex
];
_selectButton
.
selected
=
model
.
isSelected
;
_selectButton
.
selected
=
model
.
isSelected
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
selectedPhotoArr
.
count
];
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_
tzImagePickerVc
.
selectedModels
.
count
];
_numberImageView
.
hidden
=
(
_
selectedPhotoArr
.
count
<=
0
||
_isHideNaviBar
);
_numberImageView
.
hidden
=
(
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
);
_numberLable
.
hidden
=
(
_
selectedPhotoArr
.
count
<=
0
||
_isHideNaviBar
);
_numberLable
.
hidden
=
(
_
tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
);
_originalPhotoButton
.
selected
=
_isSelectOriginalPhoto
;
_originalPhotoButton
.
selected
=
_isSelectOriginalPhoto
;
_originalPhotoLable
.
hidden
=
!
_originalPhotoButton
.
isSelected
;
_originalPhotoLable
.
hidden
=
!
_originalPhotoButton
.
isSelected
;
...
...
TZImagePickerController/ViewController.m
View file @
a567b512
...
@@ -73,10 +73,11 @@
...
@@ -73,10 +73,11 @@
-
(
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
.
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.
// 你可以通过block或者代理,来得到用户选择的照片.
// 你可以通过block或者代理,来得到用户选择的照片.
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
)
{
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
}];
}];
...
@@ -105,8 +106,9 @@
...
@@ -105,8 +106,9 @@
/// User finish picking photo,if assets are not empty, user picking original photo.
/// User finish picking photo,if assets are not empty, user picking original photo.
/// 用户选择好了图片,如果assets非空,则用户选择了原图。
/// 用户选择好了图片,如果assets非空,则用户选择了原图。
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
{
-
(
void
)
imagePickerController
:(
TZImagePickerController
*
)
picker
didFinishPickingPhotos
:(
NSArray
*
)
photos
sourceAssets
:(
NSArray
*
)
assets
isSelectOriginalPhoto
:(
BOOL
)
isSelectOriginalPhoto
{
[
_selectedPhotos
addObjectsFromArray
:
photos
];
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
[
_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