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
f2f2364d
Commit
f2f2364d
authored
Jun 21, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增sortAscendingByModificationDate属性,默认为YES,照片按修改时间升序排列,为NO则拍照按钮会在第一个,照片降序排列
parent
d018bef1
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
97 additions
and
34 deletions
+97
-34
.DS_Store
.DS_Store
+0
-0
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+2
-2
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+4
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+25
-9
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
...troller/TZImagePickerController/TZImagePickerController.h
+4
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+7
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.h
...troller/TZImagePickerController/TZPhotoPickerController.h
+2
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+49
-23
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+4
-0
No files found.
.DS_Store
View file @
f2f2364d
No preview for this file type
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
f2f2364d
...
...
@@ -46,7 +46,7 @@
if
([
self
.
representedAssetIdentifier
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]])
{
self
.
imageView
.
image
=
photo
;
}
else
{
NSLog
(
@"this cell is showing other asset"
);
//
NSLog(@"this cell is showing other asset");
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
}
if
(
!
isDegraded
)
{
...
...
@@ -55,7 +55,7 @@
}];
if
(
imageRequestID
&&
self
.
imageRequestID
&&
imageRequestID
!=
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
NSLog
(
@"cancelImageRequest %d"
,
self
.
imageRequestID
);
//
NSLog(@"cancelImageRequest %d",self.imageRequestID);
}
self
.
imageRequestID
=
imageRequestID
;
self
.
selectPhotoButton
.
selected
=
model
.
isSelected
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
f2f2364d
...
...
@@ -23,6 +23,10 @@
/// Default is 600px / 默认600像素宽
@property
(
nonatomic
,
assign
)
CGFloat
photoPreviewMaxWidth
;
/// Sort photos ascending by modificationDate,Default is YES
/// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个
@property
(
nonatomic
,
assign
)
BOOL
sortAscendingByModificationDate
;
/// Return YES if Authorized 返回YES如果得到了授权
-
(
BOOL
)
authorizationStatusAuthorized
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
f2f2364d
...
...
@@ -67,12 +67,12 @@ static CGFloat TZScreenScale;
if
(
!
allowPickingVideo
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeImage
];
if
(
!
allowPickingImage
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeVideo
];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:
YES
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
YES
]];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:
self.sortAscendingByModificationDate
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeSmartAlbumUserLibrary
options
:
nil
];
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"所有照片"
])
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"所有照片"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"All Photos"
]
)
{
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
model
=
[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
];
if
(
completion
)
completion
(
model
);
...
...
@@ -83,7 +83,7 @@ static CGFloat TZScreenScale;
[
self
.
assetLibrary
enumerateGroupsWithTypes
:
ALAssetsGroupAll
usingBlock
:
^
(
ALAssetsGroup
*
group
,
BOOL
*
stop
)
{
if
([
group
numberOfAssets
]
<
1
)
return
;
NSString
*
name
=
[
group
valueForProperty
:
ALAssetsGroupPropertyName
];
if
([
name
isEqualToString
:
@"Camera Roll"
]
||
[
name
isEqualToString
:
@"相机胶卷"
]
||
[
name
isEqualToString
:
@"所有照片"
])
{
if
([
name
isEqualToString
:
@"Camera Roll"
]
||
[
name
isEqualToString
:
@"相机胶卷"
]
||
[
name
isEqualToString
:
@"所有照片"
]
||
[
name
isEqualToString
:
@"All Photos"
]
)
{
model
=
[
self
modelWithResult
:
group
name
:
name
];
if
(
completion
)
completion
(
model
);
*
stop
=
YES
;
...
...
@@ -100,8 +100,8 @@ static CGFloat TZScreenScale;
if
(
!
allowPickingImage
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeVideo
];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:
YES
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
YES
]];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:
self.sortAscendingByModificationDate
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
PHAssetCollectionSubtype
smartAlbumSubtype
=
PHAssetCollectionSubtypeSmartAlbumUserLibrary
|
PHAssetCollectionSubtypeSmartAlbumRecentlyAdded
|
PHAssetCollectionSubtypeSmartAlbumVideos
;
// For iOS 9, We need to show ScreenShots Album && SelfPortraits Album
...
...
@@ -183,7 +183,7 @@ static CGFloat TZScreenScale;
}
else
if
(
allowPickingImage
)
{
[
group
setAssetsFilter
:[
ALAssetsFilter
allPhotos
]];
}
[
group
enumerateAssetsUsingBlock
:
^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
ALAssetsGroupEnumerationResultsBlock
resultBlock
=
^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
if
(
result
==
nil
)
{
if
(
completion
)
completion
(
photoArr
);
}
...
...
@@ -202,8 +202,17 @@ static CGFloat TZScreenScale;
}
else
{
[
photoArr
addObject
:[
TZAssetModel
modelWithAsset
:
result
type
:
type
]];
}
};
if
(
self
.
sortAscendingByModificationDate
)
{
[
group
enumerateAssetsUsingBlock
:
^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
if
(
resultBlock
)
{
resultBlock
(
result
,
index
,
stop
);
}
}];
}
else
{
[
group
enumerateAssetsWithOptions
:
NSEnumerationReverse
usingBlock
:
^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
if
(
resultBlock
)
{
resultBlock
(
result
,
index
,
stop
);
}
}];
}
}
}
/// Get asset at index 获得下标为index的单个照片
...
...
@@ -387,9 +396,14 @@ static CGFloat TZScreenScale;
return
0
;
}
/// Get postImage / 获取封面图
-
(
void
)
getPostImageWithAlbumModel
:(
TZAlbumModel
*
)
model
completion
:(
void
(
^
)(
UIImage
*
))
completion
{
if
(
iOS8Later
)
{
[[
TZImageManager
manager
]
getPhotoWithAsset
:[
model
.
result
lastObject
]
photoWidth
:
80
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
id
asset
=
[
model
.
result
lastObject
];
if
(
!
self
.
sortAscendingByModificationDate
)
{
asset
=
[
model
.
result
firstObject
];
}
[[
TZImageManager
manager
]
getPhotoWithAsset
:
asset
photoWidth
:
80
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
completion
)
completion
(
photo
);
}];
}
else
{
...
...
@@ -459,6 +473,7 @@ static CGFloat TZScreenScale;
#pragma mark - Get Video
/// Get Video / 获取视频
-
(
void
)
getVideoWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
AVPlayerItem
*
_Nullable
,
NSDictionary
*
_Nullable
))
completion
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
[[
PHImageManager
defaultManager
]
requestPlayerItemForVideo
:
asset
options
:
nil
resultHandler
:^
(
AVPlayerItem
*
_Nullable
playerItem
,
NSDictionary
*
_Nullable
info
)
{
...
...
@@ -476,6 +491,7 @@ static CGFloat TZScreenScale;
#pragma mark - Export video
/// Export Video / 导出视频,暂仅仅支持iOS8.0+
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHVideoRequestOptions
*
options
=
[[
PHVideoRequestOptions
alloc
]
init
];
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
View file @
f2f2364d
...
...
@@ -34,6 +34,10 @@
/// Default is 9 / 默认最大可选9张图片
@property
(
nonatomic
,
assign
)
NSInteger
maxImagesCount
;
/// Sort photos ascending by modificationDate,Default is YES
/// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个
@property
(
nonatomic
,
assign
)
BOOL
sortAscendingByModificationDate
;
/// Default is 828px / 默认828像素宽
@property
(
nonatomic
,
assign
)
CGFloat
photoWidth
;
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
f2f2364d
...
...
@@ -89,6 +89,7 @@
self
.
timeout
=
15
;
self
.
photoWidth
=
828
.
0
;
self
.
photoPreviewMaxWidth
=
600
;
self
.
sortAscendingByModificationDate
=
YES
;
if
(
!
[[
TZImageManager
manager
]
authorizationStatusAuthorized
])
{
_tipLable
=
[[
UILabel
alloc
]
init
];
...
...
@@ -148,6 +149,7 @@
_pushToPhotoPickerVc
=
YES
;
if
(
_pushToPhotoPickerVc
)
{
TZPhotoPickerController
*
photoPickerVc
=
[[
TZPhotoPickerController
alloc
]
init
];
photoPickerVc
.
isFirstAppear
=
YES
;
[[
TZImageManager
manager
]
getCameraRollAlbum
:
self
.
allowPickingVideo
allowPickingImage
:
self
.
allowPickingImage
completion
:^
(
TZAlbumModel
*
model
)
{
photoPickerVc
.
model
=
model
;
[
self
pushViewController
:
photoPickerVc
animated
:
YES
];
...
...
@@ -251,6 +253,11 @@
[[
NSUserDefaults
standardUserDefaults
]
synchronize
];
}
-
(
void
)
setSortAscendingByModificationDate
:(
BOOL
)
sortAscendingByModificationDate
{
_sortAscendingByModificationDate
=
sortAscendingByModificationDate
;
[
TZImageManager
manager
].
sortAscendingByModificationDate
=
sortAscendingByModificationDate
;
}
-
(
void
)
pushViewController
:(
UIViewController
*
)
viewController
animated
:(
BOOL
)
animated
{
if
(
iOS7Later
)
viewController
.
automaticallyAdjustsScrollViewInsets
=
NO
;
if
(
_timer
)
{
[
_timer
invalidate
];
_timer
=
nil
;}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.h
View file @
f2f2364d
...
...
@@ -11,7 +11,9 @@
@class
TZAlbumModel
;
@interface
TZPhotoPickerController
:
UIViewController
@property
(
nonatomic
,
assign
)
BOOL
isFirstAppear
;
@property
(
nonatomic
,
strong
)
TZAlbumModel
*
model
;
@property
(
nonatomic
,
copy
)
void
(
^
backButtonClickHandle
)(
TZAlbumModel
*
model
);
@end
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
f2f2364d
...
...
@@ -26,6 +26,7 @@
UILabel
*
_originalPhotoLable
;
BOOL
_shouldScrollToBottom
;
BOOL
_showTakePhotoBtn
;
}
@property
CGRect
previousPreheatRect
;
@property
(
nonatomic
,
assign
)
BOOL
isSelectOriginalPhoto
;
...
...
@@ -66,7 +67,15 @@ static CGSize AssetGridThumbnailSize;
self
.
view
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
navigationItem
.
title
=
_model
.
name
;
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
)
{
_showTakePhotoBtn
=
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
||
[
_model
.
name
isEqualToString
:
@"All Photos"
]);
if
(
!
tzImagePickerVc
.
sortAscendingByModificationDate
&&
_isFirstAppear
&&
iOS8Later
)
{
[[
TZImageManager
manager
]
getCameraRollAlbum
:
tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
tzImagePickerVc
.
allowPickingImage
completion
:^
(
TZAlbumModel
*
model
)
{
_model
=
model
;
_models
=
[
NSMutableArray
arrayWithArray
:
_model
.
models
];
[
self
initSubviews
];
}];
}
else
{
if
(
_showTakePhotoBtn
||
!
iOS8Later
)
{
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
_models
=
[
NSMutableArray
arrayWithArray
:
models
];
[
self
initSubviews
];
...
...
@@ -75,6 +84,7 @@ static CGSize AssetGridThumbnailSize;
_models
=
[
NSMutableArray
arrayWithArray
:
_model
.
models
];
[
self
initSubviews
];
}
}
// [self resetCachedAssets];
}
...
...
@@ -111,7 +121,7 @@ static CGSize AssetGridThumbnailSize;
_collectionView
.
scrollIndicatorInsets
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
-
2
);
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
([
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
])
&&
tzImagePickerVc
.
allowTakePicture
)
{
if
(
_showTakePhotoBtn
&&
tzImagePickerVc
.
allowTakePicture
)
{
_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
);
...
...
@@ -258,7 +268,7 @@ static CGSize AssetGridThumbnailSize;
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
completion
:
^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
isDegraded
)
return
;
if
(
photo
)
{
photo
=
[
self
scaleImage
:
photo
toSize
:
CGSizeMake
(
tzImagePickerVc
.
photoWidth
,
tzImagePickerVc
.
photoWidth
*
photo
.
size
.
height
/
photo
.
size
.
width
)];
photo
=
[
self
scaleImage
:
photo
toSize
:
CGSizeMake
(
tzImagePickerVc
.
photoWidth
,
(
int
)(
tzImagePickerVc
.
photoWidth
*
photo
.
size
.
height
/
photo
.
size
.
width
)
)];
[
photos
replaceObjectAtIndex
:
i
withObject
:
photo
];
}
if
(
info
)
[
infoArr
replaceObjectAtIndex
:
i
withObject
:
info
];
...
...
@@ -287,7 +297,7 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - UICollectionViewDataSource && Delegate
-
(
NSInteger
)
collectionView
:(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:(
NSInteger
)
section
{
if
(
[
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
if
(
_showTakePhotoBtn
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
allowPickingImage
&&
tzImagePickerVc
.
allowTakePicture
)
{
return
_models
.
count
+
1
;
...
...
@@ -298,14 +308,20 @@ static CGSize AssetGridThumbnailSize;
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// the cell lead to take a picture / 去拍照的cell
if
(
indexPath
.
row
>=
_models
.
count
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(((
tzImagePickerVc
.
sortAscendingByModificationDate
&&
indexPath
.
row
>=
_models
.
count
)
||
(
!
tzImagePickerVc
.
sortAscendingByModificationDate
&&
indexPath
.
row
==
0
))
&&
_showTakePhotoBtn
)
{
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
];
TZAssetModel
*
model
=
_models
[
indexPath
.
row
];
TZAssetModel
*
model
;
if
(
tzImagePickerVc
.
sortAscendingByModificationDate
||
!
_showTakePhotoBtn
)
{
model
=
_models
[
indexPath
.
row
];
}
else
{
model
=
_models
[
indexPath
.
row
-
1
];
}
cell
.
model
=
model
;
__weak
typeof
(
cell
)
weakCell
=
cell
;
...
...
@@ -319,7 +335,7 @@ static CGSize AssetGridThumbnailSize;
model
.
isSelected
=
NO
;
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([
model
.
asset
isEqual
:
model_item
.
asset
])
{
if
([
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model_item
.
asset
]
])
{
[
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
}
}
...
...
@@ -342,12 +358,16 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
// take a picture / 去拍照
if
(
indexPath
.
row
>=
_models
.
count
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(((
tzImagePickerVc
.
sortAscendingByModificationDate
&&
indexPath
.
row
>=
_models
.
count
)
||
(
!
tzImagePickerVc
.
sortAscendingByModificationDate
&&
indexPath
.
row
==
0
))
&&
_showTakePhotoBtn
)
{
[
self
takePicture
];
return
;
}
// preview phote or video / 预览照片或视频
TZAssetModel
*
model
=
_models
[
indexPath
.
row
];
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
NSInteger
index
=
indexPath
.
row
;
if
(
!
tzImagePickerVc
.
sortAscendingByModificationDate
&&
_showTakePhotoBtn
)
{
index
=
indexPath
.
row
-
1
;
}
TZAssetModel
*
model
=
_models
[
index
];
if
(
model
.
type
==
TZAssetModelMediaTypeVideo
)
{
if
(
tzImagePickerVc
.
selectedModels
.
count
>
0
)
{
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
...
...
@@ -359,7 +379,7 @@ static CGSize AssetGridThumbnailSize;
}
}
else
{
TZPhotoPreviewController
*
photoPreviewVc
=
[[
TZPhotoPreviewController
alloc
]
init
];
photoPreviewVc
.
currentIndex
=
index
Path
.
row
;
photoPreviewVc
.
currentIndex
=
index
;
photoPreviewVc
.
models
=
_models
;
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
}
...
...
@@ -409,7 +429,6 @@ static CGSize AssetGridThumbnailSize;
photoPreviewVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
photoPreviewVc
.
backButtonClickBlock
=
^
(
BOOL
isSelectOriginalPhoto
)
{
weakSelf
.
isSelectOriginalPhoto
=
isSelectOriginalPhoto
;
[
weakSelf
checkSelectedModels
];
[
weakSelf
.
collectionView
reloadData
];
[
weakSelf
refreshBottomToolBarStatus
];
};
...
...
@@ -440,9 +459,10 @@ static CGSize AssetGridThumbnailSize;
}
-
(
void
)
scrollCollectionViewToBottom
{
if
(
_shouldScrollToBottom
&&
_models
.
count
>
0
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_shouldScrollToBottom
&&
_models
.
count
>
0
&&
tzImagePickerVc
.
sortAscendingByModificationDate
)
{
NSInteger
item
=
_models
.
count
-
1
;
if
(
[
_model
.
name
isEqualToString
:
@"相机胶卷"
]
||
[
_model
.
name
isEqualToString
:
@"Camera Roll"
]
||
[
_model
.
name
isEqualToString
:
@"所有照片"
]
)
{
if
(
_showTakePhotoBtn
)
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
allowPickingImage
&&
tzImagePickerVc
.
allowTakePicture
)
{
item
+=
1
;
...
...
@@ -489,11 +509,17 @@ static CGSize AssetGridThumbnailSize;
[[
TZImageManager
manager
]
getAssetsFromFetchResult
:
_model
.
result
allowPickingVideo
:
tzImagePickerVc
.
allowPickingVideo
allowPickingImage
:
tzImagePickerVc
.
allowPickingImage
completion
:^
(
NSArray
<
TZAssetModel
*>
*
models
)
{
[
tzImagePickerVc
hideProgressHUD
];
TZAssetModel
*
model
=
[
models
lastObject
];
[
_models
addObject
:
model
];
TZAssetModel
*
assetModel
;
if
(
tzImagePickerVc
.
sortAscendingByModificationDate
)
{
assetModel
=
[
models
lastObject
];
[
_models
addObject
:
assetModel
];
}
else
{
assetModel
=
[
models
firstObject
];
[
_models
insertObject
:
assetModel
atIndex
:
0
];
}
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
m
odel
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
m
odel
];
assetM
odel
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
assetM
odel
];
[
self
refreshBottomToolBarStatus
];
}
[
_collectionView
reloadData
];
...
...
TZImagePickerController/ViewController.m
View file @
f2f2364d
...
...
@@ -122,6 +122,8 @@
-
(
IBAction
)
pickPhotoButtonClick
:(
UIButton
*
)
sender
{
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
9
delegate
:
self
];
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
// tip:如果你需要将拍照放在外面,不要传这个参数
imagePickerVc
.
selectedAssets
=
_selectedAssets
;
// optional, 可选的
// imagePickerVc.allowTakePicture = NO; // 隐藏拍照按钮
...
...
@@ -143,6 +145,8 @@
// imagePickerVc.allowPickingImage = NO;
// imagePickerVc.allowPickingOriginalPhoto = NO;
imagePickerVc
.
sortAscendingByModificationDate
=
NO
;
[
self
presentViewController
:
imagePickerVc
animated
:
YES
completion
:
nil
];
}
...
...
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