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
452babd8
Commit
452babd8
authored
May 07, 2018
by
yuzheng.tz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增是否显示图片选中序号的属性
parent
7fa5ea76
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
286 additions
and
65 deletions
+286
-65
TZImagePickerController/Base.lproj/Main.storyboard
TZImagePickerController/Base.lproj/Main.storyboard
+20
-1
TZImagePickerController/TZImagePickerController/TZAssetCell.h
...agePickerController/TZImagePickerController/TZAssetCell.h
+4
-3
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+65
-25
TZImagePickerController/TZImagePickerController/TZAssetModel.h
...gePickerController/TZImagePickerController/TZAssetModel.h
+2
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
...troller/TZImagePickerController/TZImagePickerController.h
+27
-8
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+81
-4
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+37
-12
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
...roller/TZImagePickerController/TZPhotoPreviewController.m
+43
-11
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+7
-1
No files found.
TZImagePickerController/Base.lproj/Main.storyboard
View file @
452babd8
...
...
@@ -22,7 +22,7 @@
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<subviews>
<scrollView
clipsSubviews=
"YES"
multipleTouchEnabled=
"YES"
contentMode=
"scaleToFill"
ambiguous=
"YES"
keyboardDismissMode=
"onDrag"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"AMD-xf-cz2"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"375"
height=
"
4
40"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"375"
height=
"
6
40"
/>
<subviews>
<view
contentMode=
"scaleToFill"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"obE-hs-XLa"
userLabel=
"View1"
>
<rect
key=
"frame"
x=
"0.0"
y=
"20"
width=
"375"
height=
"35"
/>
...
...
@@ -283,6 +283,24 @@
</subviews>
<color
key=
"backgroundColor"
red=
"1"
green=
"1"
blue=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</view>
<view
contentMode=
"scaleToFill"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"fWM-jc-1VU"
userLabel=
"View14"
>
<rect
key=
"frame"
x=
"0.0"
y=
"475"
width=
"375"
height=
"35"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
<subviews>
<switch
opaque=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"750"
verticalHuggingPriority=
"750"
fixedFrame=
"YES"
contentHorizontalAlignment=
"center"
contentVerticalAlignment=
"center"
on=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"XsY-NI-Txd"
>
<rect
key=
"frame"
x=
"225"
y=
"2"
width=
"51"
height=
"31"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
</switch>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
fixedFrame=
"YES"
text=
"右上角显示图片选中序号"
textAlignment=
"right"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"nm2-mT-siy"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"35"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
<color
key=
"backgroundColor"
red=
"1"
green=
"1"
blue=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</view>
</subviews>
<constraints>
<constraint
firstItem=
"VUP-wm-Ah2"
firstAttribute=
"leading"
secondItem=
"PA2-zk-4Ey"
secondAttribute=
"leading"
id=
"1iv-97-UAf"
/>
...
...
@@ -360,6 +378,7 @@
<outlet
property=
"maxCountTF"
destination=
"37K-cO-hgf"
id=
"776-gE-tea"
/>
<outlet
property=
"needCircleCropSwitch"
destination=
"hsH-wt-l1R"
id=
"SVP-EE-wgf"
/>
<outlet
property=
"scrollView"
destination=
"AMD-xf-cz2"
id=
"0Bb-Te-K4h"
/>
<outlet
property=
"showSelectedIndexSwitch"
destination=
"XsY-NI-Txd"
id=
"ou9-YO-ebP"
/>
<outlet
property=
"showSheetSwitch"
destination=
"uHt-bT-lBZ"
id=
"NxK-wM-ivE"
/>
<outlet
property=
"showTakePhotoBtnSwitch"
destination=
"jpa-B9-8n6"
id=
"lh8-2O-IWS"
/>
<outlet
property=
"showTakeVideoBtnSwitch"
destination=
"mMy-bi-cIJ"
id=
"jER-Fp-aOr"
/>
...
...
TZImagePickerController/TZImagePickerController/TZAssetCell.h
View file @
452babd8
...
...
@@ -22,6 +22,7 @@ typedef enum : NSUInteger {
@property
(
weak
,
nonatomic
)
UIButton
*
selectPhotoButton
;
@property
(
nonatomic
,
strong
)
TZAssetModel
*
model
;
@property
(
assign
,
nonatomic
)
NSInteger
index
;
@property
(
nonatomic
,
copy
)
void
(
^
didSelectPhotoBlock
)(
BOOL
);
@property
(
nonatomic
,
assign
)
TZAssetCellType
type
;
@property
(
nonatomic
,
assign
)
BOOL
allowPickingGif
;
...
...
@@ -29,12 +30,12 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
copy
)
NSString
*
representedAssetIdentifier
;
@property
(
nonatomic
,
assign
)
int32_t
imageRequestID
;
@property
(
nonatomic
,
copy
)
NSString
*
photoSelImageNam
e
;
@property
(
nonatomic
,
copy
)
NSString
*
photoDefImageNam
e
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoSelImag
e
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoDefImag
e
;
@property
(
nonatomic
,
assign
)
BOOL
showSelectBtn
;
@property
(
assign
,
nonatomic
)
BOOL
allowPreview
;
@property
(
assign
,
nonatomic
)
BOOL
useCachedImage
;
@end
...
...
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
452babd8
...
...
@@ -16,6 +16,7 @@
@interface
TZAssetCell
()
@property
(
weak
,
nonatomic
)
UIImageView
*
imageView
;
// The photo / 照片
@property
(
weak
,
nonatomic
)
UIImageView
*
selectImageView
;
@property
(
weak
,
nonatomic
)
UILabel
*
indexLabel
;
@property
(
weak
,
nonatomic
)
UIView
*
bottomView
;
@property
(
weak
,
nonatomic
)
UILabel
*
timeLength
;
...
...
@@ -31,32 +32,39 @@
if
(
iOS8Later
)
{
self
.
representedAssetIdentifier
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
}
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
self
->
_progressView
)
{
self
.
progressView
.
hidden
=
YES
;
self
.
imageView
.
alpha
=
1
.
0
;
}
// Set the cell's thumbnail image if it's still showing the same asset.
if
(
!
iOS8Later
)
{
self
.
imageView
.
image
=
photo
;
return
;
}
if
([
self
.
representedAssetIdentifier
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]])
{
self
.
imageView
.
image
=
photo
;
}
else
{
// NSLog(@"this cell is showing other asset");
if
(
self
.
useCachedImage
&&
model
.
cachedImage
)
{
self
.
imageView
.
image
=
model
.
cachedImage
;
}
else
{
int32_t
imageRequestID
=
[[
TZImageManager
manager
]
getPhotoWithAsset
:
model
.
asset
photoWidth
:
self
.
tz_width
completion
:^
(
UIImage
*
photo
,
NSDictionary
*
info
,
BOOL
isDegraded
)
{
if
(
self
->
_progressView
)
{
self
.
progressView
.
hidden
=
YES
;
self
.
imageView
.
alpha
=
1
.
0
;
}
// Set the cell's thumbnail image if it's still showing the same asset.
if
(
!
iOS8Later
)
{
self
.
imageView
.
image
=
photo
;
return
;
}
if
([
self
.
representedAssetIdentifier
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]])
{
self
.
imageView
.
image
=
photo
;
}
else
{
// NSLog(@"this cell is showing other asset");
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
}
if
(
!
isDegraded
)
{
self
.
imageRequestID
=
0
;
}
self
.
model
.
cachedImage
=
photo
;
}
progressHandler
:
nil
networkAccessAllowed
:
NO
];
if
(
imageRequestID
&&
self
.
imageRequestID
&&
imageRequestID
!=
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
}
if
(
!
isDegraded
)
{
self
.
imageRequestID
=
0
;
}
}
progressHandler
:
nil
networkAccessAllowed
:
NO
];
if
(
imageRequestID
&&
self
.
imageRequestID
&&
imageRequestID
!=
self
.
imageRequestID
)
{
[[
PHImageManager
defaultManager
]
cancelImageRequest
:
self
.
imageRequestID
];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
self
.
imageRequestID
=
imageRequestID
;
}
self
.
imageRequestID
=
imageRequestID
;
self
.
selectPhotoButton
.
selected
=
model
.
isSelected
;
self
.
selectImageView
.
image
=
self
.
selectPhotoButton
.
isSelected
?
[
UIImage
imageNamedFromMyBundle
:
self
.
photoSelImageName
]
:
[
UIImage
imageNamedFromMyBundle
:
self
.
photoDefImageName
];
self
.
selectImageView
.
image
=
self
.
selectPhotoButton
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
self
.
indexLabel
.
hidden
=
!
self
.
selectPhotoButton
.
isSelected
;
self
.
type
=
(
NSInteger
)
model
.
type
;
// 让宽度/高度小于 最小可选照片尺寸 的图片不能选中
if
(
!
[[
TZImageManager
manager
]
isPhotoSelectableWithAsset
:
model
.
asset
])
{
...
...
@@ -69,9 +77,19 @@
if
(
model
.
isSelected
)
{
[
self
fetchBigImage
];
}
if
(
model
.
needOscillatoryAnimation
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
self
.
selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
model
.
needOscillatoryAnimation
=
NO
;
}
[
self
setNeedsLayout
];
}
-
(
void
)
setIndex
:(
NSInteger
)
index
{
_index
=
index
;
self
.
indexLabel
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
index
];
[
self
.
contentView
bringSubviewToFront
:
self
.
indexLabel
];
}
-
(
void
)
setShowSelectBtn
:(
BOOL
)
showSelectBtn
{
_showSelectBtn
=
showSelectBtn
;
if
(
!
self
.
selectPhotoButton
.
hidden
)
{
...
...
@@ -112,9 +130,11 @@
if
(
self
.
didSelectPhotoBlock
)
{
self
.
didSelectPhotoBlock
(
sender
.
isSelected
);
}
self
.
selectImageView
.
image
=
sender
.
isSelected
?
[
UIImage
imageNamedFromMyBundle
:
self
.
photoSelImageName
]
:
[
UIImage
imageNamedFromMyBundle
:
self
.
photoDefImageName
]
;
self
.
selectImageView
.
image
=
sender
.
isSelected
?
self
.
photoSelImage
:
self
.
photoDefImage
;
if
(
sender
.
isSelected
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
if
(
!
[
TZImagePickerConfig
sharedInstance
].
showSelectedIndex
)
{
[
UIView
showOscillatoryAnimationWithLayer
:
_selectImageView
.
layer
type
:
TZOscillatoryAnimationToBigger
];
}
// 用户选中了该图片,提前获取一下大图
[
self
fetchBigImage
];
}
else
{
// 取消选中,取消大图的获取
...
...
@@ -180,6 +200,8 @@
-
(
UIImageView
*
)
selectImageView
{
if
(
_selectImageView
==
nil
)
{
UIImageView
*
selectImageView
=
[[
UIImageView
alloc
]
init
];
selectImageView
.
contentMode
=
UIViewContentModeCenter
;
selectImageView
.
clipsToBounds
=
YES
;
[
self
.
contentView
addSubview
:
selectImageView
];
_selectImageView
=
selectImageView
;
}
...
...
@@ -219,6 +241,18 @@
return
_timeLength
;
}
-
(
UILabel
*
)
indexLabel
{
if
(
_indexLabel
==
nil
)
{
UILabel
*
indexLabel
=
[[
UILabel
alloc
]
init
];
indexLabel
.
font
=
[
UIFont
systemFontOfSize
:
14
];
indexLabel
.
textColor
=
[
UIColor
whiteColor
];
indexLabel
.
textAlignment
=
NSTextAlignmentCenter
;
[
self
.
contentView
addSubview
:
indexLabel
];
_indexLabel
=
indexLabel
;
}
return
_indexLabel
;
}
-
(
TZProgressView
*
)
progressView
{
if
(
_progressView
==
nil
)
{
_progressView
=
[[
TZProgressView
alloc
]
init
];
...
...
@@ -235,7 +269,13 @@
}
else
{
_selectPhotoButton
.
frame
=
self
.
bounds
;
}
_selectImageView
.
frame
=
CGRectMake
(
self
.
tz_width
-
27
,
0
,
27
,
27
);
_selectImageView
.
frame
=
CGRectMake
(
self
.
tz_width
-
27
,
3
,
24
,
24
);
if
(
_selectImageView
.
image
.
size
.
width
<=
27
)
{
_selectImageView
.
contentMode
=
UIViewContentModeCenter
;
}
else
{
_selectImageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
}
_indexLabel
.
frame
=
_selectImageView
.
frame
;
_imageView
.
frame
=
CGRectMake
(
0
,
0
,
self
.
tz_width
,
self
.
tz_height
);
static
CGFloat
progressWH
=
20
;
...
...
TZImagePickerController/TZImagePickerController/TZAssetModel.h
View file @
452babd8
...
...
@@ -23,7 +23,9 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
strong
)
id
asset
;
///< PHAsset or ALAsset
@property
(
nonatomic
,
assign
)
BOOL
isSelected
;
///< The select status of a photo, default is No
@property
(
nonatomic
,
assign
)
TZAssetModelMediaType
type
;
@property
(
assign
,
nonatomic
)
BOOL
needOscillatoryAnimation
;
@property
(
nonatomic
,
copy
)
NSString
*
timeLength
;
@property
(
strong
,
nonatomic
)
UIImage
*
cachedImage
;
/// Init a photo dataModel With a asset
/// 用一个PHAsset/ALAsset实例,初始化一个照片模型
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.h
View file @
452babd8
...
...
@@ -114,14 +114,21 @@
/// 默认为YES,如果设置为NO, 选择器将不会自己dismiss
@property
(
nonatomic
,
assign
)
BOOL
autoDismiss
;
/// Default is
YES, if set NO
, in the delegate method the photos and infos will be nil, only assets hava value.
/// Default is
NO, if set YES
, in the delegate method the photos and infos will be nil, only assets hava value.
/// 默认为NO,如果设置为YES,代理方法里photos和infos会是nil,只返回assets
@property
(
assign
,
nonatomic
)
BOOL
onlyReturnAsset
;
/// Default is NO, if set YES, will show the image's selected index.
/// 默认为NO,如果设置为YES,会显示照片的选中序号
@property
(
assign
,
nonatomic
)
BOOL
showSelectedIndex
;
/// The photos user have selected
/// 用户选中过的图片数组
@property
(
nonatomic
,
strong
)
NSMutableArray
*
selectedAssets
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
TZAssetModel
*>
*
selectedModels
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
selectedAssetIds
;
-
(
void
)
addSelectedModel
:(
TZAssetModel
*
)
model
;
-
(
void
)
removeSelectedModel
:(
TZAssetModel
*
)
model
;
/// Minimum selectable photo width, Default is 0
/// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中
...
...
@@ -158,13 +165,20 @@
@property
(
assign
,
nonatomic
)
BOOL
needShowStatusBar
;
#pragma mark -
@property
(
nonatomic
,
copy
)
NSString
*
takePictureImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoSelImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoDefImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoOriginSelImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoOriginDefImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoPreviewOriginDefImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoNumberIconImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
takePictureImageName
__attribute__
((
deprecated
(
"Use -takePictureImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoSelImageName
__attribute__
((
deprecated
(
"Use -photoSelImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoDefImageName
__attribute__
((
deprecated
(
"Use -photoDefImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoOriginSelImageName
__attribute__
((
deprecated
(
"Use -photoOriginSelImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoOriginDefImageName
__attribute__
((
deprecated
(
"Use -photoOriginDefImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoPreviewOriginDefImageName
__attribute__
((
deprecated
(
"Use -photoPreviewOriginDefImage."
)));
@property
(
nonatomic
,
copy
)
NSString
*
photoNumberIconImageName
__attribute__
((
deprecated
(
"Use -photoNumberIconImage."
)));
@property
(
nonatomic
,
strong
)
UIImage
*
takePictureImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoSelImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoDefImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoOriginSelImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoOriginDefImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoPreviewOriginDefImage
;
@property
(
nonatomic
,
strong
)
UIImage
*
photoNumberIconImage
;
#pragma mark -
/// Appearance / 外观颜色 + 按钮文字
...
...
@@ -183,6 +197,10 @@
@property
(
nonatomic
,
copy
)
NSString
*
settingBtnTitleStr
;
@property
(
nonatomic
,
copy
)
NSString
*
processHintStr
;
/// Icon theme color, default is green color like wechat, the value is r:31 g:185 b:34. Currently only support image selection icon when showSelectedIndex is YES
/// icon主题色,默认是微信的绿色,值是r:31 g:185 b:34。目前仅支持showSelectedIndex为YES时的图片选中icon
@property
(
strong
,
nonatomic
)
UIColor
*
iconThemeColor
;
#pragma mark -
-
(
void
)
cancelButtonClick
;
...
...
@@ -286,4 +304,5 @@
@property
(
strong
,
nonatomic
)
NSBundle
*
languageBundle
;
/// 默认是200,如果一个GIF过大,里面图片个数可能超过1000,会导致内存飙升而崩溃
@property
(
assign
,
nonatomic
)
NSInteger
gifPreviewMaxImagesCount
;
@property
(
assign
,
nonatomic
)
BOOL
showSelectedIndex
;
@end
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
452babd8
...
...
@@ -278,7 +278,7 @@
self
.
allowPreview
=
YES
;
self
.
statusBarStyle
=
UIStatusBarStyleLightContent
;
[
self
configDefaultImageName
];
self
.
iconThemeColor
=
[
UIColor
colorWithRed
:
31
/
255
.
0
green
:
185
/
255
.
0
blue
:
34
/
255
.
0
alpha
:
1
.
0
];
[
self
configDefaultBtnTitle
];
CGFloat
cropViewWH
=
MIN
(
self
.
view
.
tz_width
,
self
.
view
.
tz_height
)
/
3
*
2
;
...
...
@@ -289,12 +289,52 @@
self
.
takePictureImageName
=
@"takePicture80"
;
self
.
photoSelImageName
=
@"photo_sel_photoPickerVc"
;
self
.
photoDefImageName
=
@"photo_def_photoPickerVc"
;
self
.
photoNumberIconImage
Name
=
@"photo_number_icon"
;
self
.
photoNumberIconImage
=
[
self
createImageWithColor
:
nil
size
:
CGSizeMake
(
48
,
48
)
radius
:
24
];
//
@"photo_number_icon";
self
.
photoPreviewOriginDefImageName
=
@"preview_original_def"
;
self
.
photoOriginDefImageName
=
@"photo_original_def"
;
self
.
photoOriginSelImageName
=
@"photo_original_sel"
;
}
-
(
void
)
setTakePictureImageName
:(
NSString
*
)
takePictureImageName
{
_takePictureImageName
=
takePictureImageName
;
_takePictureImage
=
[
UIImage
imageNamedFromMyBundle
:
takePictureImageName
];
}
-
(
void
)
setPhotoSelImageName
:(
NSString
*
)
photoSelImageName
{
_photoSelImageName
=
photoSelImageName
;
_photoSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoSelImageName
];
}
-
(
void
)
setPhotoDefImageName
:(
NSString
*
)
photoDefImageName
{
_photoDefImageName
=
photoDefImageName
;
_photoDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoDefImageName
];
}
-
(
void
)
setPhotoNumberIconImageName
:(
NSString
*
)
photoNumberIconImageName
{
_photoNumberIconImageName
=
photoNumberIconImageName
;
_photoNumberIconImage
=
[
UIImage
imageNamedFromMyBundle
:
photoNumberIconImageName
];
}
-
(
void
)
setPhotoPreviewOriginDefImageName
:(
NSString
*
)
photoPreviewOriginDefImageName
{
_photoPreviewOriginDefImageName
=
photoPreviewOriginDefImageName
;
_photoPreviewOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoPreviewOriginDefImageName
];
}
-
(
void
)
setPhotoOriginDefImageName
:(
NSString
*
)
photoOriginDefImageName
{
_photoOriginDefImageName
=
photoOriginDefImageName
;
_photoOriginDefImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginDefImageName
];
}
-
(
void
)
setPhotoOriginSelImageName
:(
NSString
*
)
photoOriginSelImageName
{
_photoOriginSelImageName
=
photoOriginSelImageName
;
_photoOriginSelImage
=
[
UIImage
imageNamedFromMyBundle
:
photoOriginSelImageName
];
}
-
(
void
)
setIconThemeColor
:(
UIColor
*
)
iconThemeColor
{
_iconThemeColor
=
iconThemeColor
;
[
self
configDefaultImageName
];
}
-
(
void
)
configDefaultBtnTitle
{
self
.
doneBtnTitleStr
=
[
NSBundle
tz_localizedStringForKey
:
@"Done"
];
self
.
cancelBtnTitleStr
=
[
NSBundle
tz_localizedStringForKey
:
@"Cancel"
];
...
...
@@ -304,6 +344,14 @@
self
.
processHintStr
=
[
NSBundle
tz_localizedStringForKey
:
@"Processing..."
];
}
-
(
void
)
setShowSelectedIndex
:(
BOOL
)
showSelectedIndex
{
_showSelectedIndex
=
showSelectedIndex
;
if
(
showSelectedIndex
)
{
self
.
photoSelImage
=
[
self
createImageWithColor
:
nil
size
:
CGSizeMake
(
48
,
48
)
radius
:
24
];
}
[
TZImagePickerConfig
sharedInstance
].
showSelectedIndex
=
showSelectedIndex
;
}
-
(
void
)
observeAuthrizationStatusChange
{
[
_timer
invalidate
];
_timer
=
nil
;
...
...
@@ -500,10 +548,11 @@
-
(
void
)
setSelectedAssets
:(
NSMutableArray
*
)
selectedAssets
{
_selectedAssets
=
selectedAssets
;
_selectedModels
=
[
NSMutableArray
array
];
_selectedAssetIds
=
[
NSMutableArray
array
];
for
(
id
asset
in
selectedAssets
)
{
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:[[
TZImageManager
manager
]
getAssetType
:
asset
]];
model
.
isSelected
=
YES
;
[
_selectedModels
addObject
:
model
];
[
self
addSelectedModel
:
model
];
}
}
...
...
@@ -555,6 +604,34 @@
// NSLog(@"%@ dealloc",NSStringFromClass(self.class));
}
-
(
void
)
addSelectedModel
:(
TZAssetModel
*
)
model
{
[
_selectedModels
addObject
:
model
];
NSString
*
assetId
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
[
_selectedAssetIds
addObject
:
assetId
];
}
-
(
void
)
removeSelectedModel
:(
TZAssetModel
*
)
model
{
[
_selectedModels
removeObject
:
model
];
NSString
*
assetId
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
[
_selectedAssetIds
removeObject
:
assetId
];
}
-
(
UIImage
*
)
createImageWithColor
:(
UIColor
*
)
color
size
:(
CGSize
)
size
radius
:(
CGFloat
)
radius
{
if
(
!
color
)
{
color
=
self
.
iconThemeColor
;
}
CGRect
rect
=
CGRectMake
(
0
.
0
f
,
0
.
0
f
,
size
.
width
,
size
.
height
);
UIGraphicsBeginImageContextWithOptions
(
rect
.
size
,
NO
,
[
UIScreen
mainScreen
].
scale
);
CGContextRef
context
=
UIGraphicsGetCurrentContext
();
CGContextSetFillColorWithColor
(
context
,
[
color
CGColor
]);
UIBezierPath
*
path
=
[
UIBezierPath
bezierPathWithRoundedRect
:
rect
cornerRadius
:
radius
];
CGContextAddPath
(
context
,
path
.
CGPath
);
CGContextFillPath
(
context
);
UIImage
*
image
=
UIGraphicsGetImageFromCurrentImageContext
();
UIGraphicsEndImageContext
();
return
image
;
}
#pragma mark - UIContentContainer
-
(
void
)
viewWillTransitionToSize
:(
CGSize
)
size
withTransitionCoordinator
:(
id
<
UIViewControllerTransitionCoordinator
>
)
coordinator
{
...
...
@@ -724,7 +801,7 @@
-
(
UITableViewCell
*
)
tableView
:(
UITableView
*
)
tableView
cellForRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
TZAlbumCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
@"TZAlbumCell"
];
TZImagePickerController
*
imagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
cell
.
selectedCountButton
.
backgroundColor
=
imagePickerVc
.
oKButtonTitleColorNormal
;
cell
.
selectedCountButton
.
backgroundColor
=
imagePickerVc
.
iconThemeColor
;
cell
.
model
=
_albumArr
[
indexPath
.
row
];
cell
.
accessoryType
=
UITableViewCellAccessoryDisclosureIndicator
;
return
cell
;
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
452babd8
...
...
@@ -41,6 +41,7 @@
@property
(
strong
,
nonatomic
)
UICollectionViewFlowLayout
*
layout
;
@property
(
nonatomic
,
strong
)
UIImagePickerController
*
imagePickerVc
;
@property
(
strong
,
nonatomic
)
CLLocation
*
location
;
@property
(
assign
,
nonatomic
)
BOOL
useCachedImage
;
@end
static
CGSize
AssetGridThumbnailSize
;
...
...
@@ -210,8 +211,10 @@ static CGFloat itemMargin = 5;
[
_originalPhotoButton
setTitle
:
tzImagePickerVc
.
fullImageBtnTitleStr
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setTitleColor
:[
UIColor
lightGrayColor
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoOriginDefImageName
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoOriginSelImageName
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:
tzImagePickerVc
.
photoOriginDefImage
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:
tzImagePickerVc
.
photoOriginSelImage
forState
:
UIControlStateSelected
];
_originalPhotoButton
.
imageView
.
clipsToBounds
=
YES
;
_originalPhotoButton
.
imageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
_originalPhotoButton
.
selected
=
_isSelectOriginalPhoto
;
_originalPhotoButton
.
enabled
=
tzImagePickerVc
.
selectedModels
.
count
>
0
;
...
...
@@ -231,8 +234,10 @@ static CGFloat itemMargin = 5;
[
_doneButton
setTitleColor
:
tzImagePickerVc
.
oKButtonTitleColorDisabled
forState
:
UIControlStateDisabled
];
_doneButton
.
enabled
=
tzImagePickerVc
.
selectedModels
.
count
||
tzImagePickerVc
.
alwaysEnableDoneBtn
;
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:
[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoNumberIconImageName
]
];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:
tzImagePickerVc
.
photoNumberIconImage
];
_numberImageView
.
hidden
=
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberImageView
.
clipsToBounds
=
YES
;
_numberImageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberLabel
=
[[
UILabel
alloc
]
init
];
...
...
@@ -308,8 +313,8 @@ static CGFloat itemMargin = 5;
_originalPhotoLabel
.
frame
=
CGRectMake
(
fullImageWidth
+
46
,
0
,
80
,
50
);
}
[
_doneButton
sizeToFit
];
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
_doneButton
.
tz_width
-
12
,
0
,
_doneButton
.
tz_width
,
44
);
_numberImageView
.
frame
=
CGRectMake
(
_doneButton
.
tz_left
-
30
-
2
,
7
,
30
,
30
);
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
_doneButton
.
tz_width
-
12
,
0
,
_doneButton
.
tz_width
,
50
);
_numberImageView
.
frame
=
CGRectMake
(
_doneButton
.
tz_left
-
24
-
5
,
13
,
24
,
24
);
_numberLabel
.
frame
=
_numberImageView
.
frame
;
_divideLine
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
1
);
...
...
@@ -456,7 +461,7 @@ static CGFloat itemMargin = 5;
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
:
tzImagePickerVc
.
takePictureImageName
]
;
cell
.
imageView
.
image
=
tzImagePickerVc
.
takePictureImage
;
if
([
tzImagePickerVc
.
takePictureImageName
isEqualToString
:
@"takePicture80"
])
{
cell
.
imageView
.
contentMode
=
UIViewContentModeCenter
;
CGFloat
rgb
=
223
/
255
.
0
;
...
...
@@ -469,8 +474,9 @@ static CGFloat itemMargin = 5;
// the cell dipaly photo or video / 展示照片或视频的cell
TZAssetCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZAssetCell"
forIndexPath
:
indexPath
];
cell
.
allowPickingMultipleVideo
=
tzImagePickerVc
.
allowPickingMultipleVideo
;
cell
.
photoDefImageName
=
tzImagePickerVc
.
photoDefImageName
;
cell
.
photoSelImageName
=
tzImagePickerVc
.
photoSelImageName
;
cell
.
photoDefImage
=
tzImagePickerVc
.
photoDefImage
;
cell
.
photoSelImage
=
tzImagePickerVc
.
photoSelImage
;
cell
.
useCachedImage
=
self
.
useCachedImage
;
TZAssetModel
*
model
;
if
(
tzImagePickerVc
.
sortAscendingByModificationDate
||
!
_showTakePhotoBtn
)
{
model
=
_models
[
indexPath
.
row
];
...
...
@@ -479,6 +485,10 @@ static CGFloat itemMargin = 5;
}
cell
.
allowPickingGif
=
tzImagePickerVc
.
allowPickingGif
;
cell
.
model
=
model
;
if
(
model
.
isSelected
&&
tzImagePickerVc
.
showSelectedIndex
)
{
NSString
*
assetId
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
cell
.
index
=
[
tzImagePickerVc
.
selectedAssetIds
indexOfObject
:
assetId
]
+
1
;
}
cell
.
showSelectBtn
=
tzImagePickerVc
.
showSelectBtn
;
cell
.
allowPreview
=
tzImagePickerVc
.
allowPreview
;
...
...
@@ -497,17 +507,24 @@ static CGFloat itemMargin = 5;
NSArray
*
selectedModels
=
[
NSArray
arrayWithArray
:
tzImagePickerVc
.
selectedModels
];
for
(
TZAssetModel
*
model_item
in
selectedModels
)
{
if
([[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
]
isEqualToString
:[[
TZImageManager
manager
]
getAssetIdentifier
:
model_item
.
asset
]])
{
[
tzImagePickerVc
.
selectedModels
removeObject
:
model_item
];
[
tzImagePickerVc
removeSelectedModel
:
model_item
];
break
;
}
}
[
strongSelf
refreshBottomToolBarStatus
];
if
(
tzImagePickerVc
.
showSelectedIndex
)
{
[
strongSelf
setUseCachedImageAndReloadData
];
}
}
else
{
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
strongCell
.
selectPhotoButton
.
selected
=
YES
;
model
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
model
];
if
(
tzImagePickerVc
.
showSelectedIndex
)
{
model
.
needOscillatoryAnimation
=
YES
;
[
strongSelf
setUseCachedImageAndReloadData
];
}
[
tzImagePickerVc
addSelectedModel
:
model
];
[
strongSelf
refreshBottomToolBarStatus
];
}
else
{
NSString
*
title
=
[
NSString
stringWithFormat
:[
NSBundle
tz_localizedStringForKey
:
@"Select a maximum of %zd photos"
],
tzImagePickerVc
.
maxImagesCount
];
...
...
@@ -567,6 +584,14 @@ static CGFloat itemMargin = 5;
#pragma mark - Private Method
-
(
void
)
setUseCachedImageAndReloadData
{
self
.
useCachedImage
=
YES
;
[
self
.
collectionView
reloadData
];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
5
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
self
.
useCachedImage
=
NO
;
});
}
/// 拍照按钮点击事件
-
(
void
)
takePhoto
{
AVAuthorizationStatus
authStatus
=
[
AVCaptureDevice
authorizationStatusForMediaType
:
AVMediaTypeVideo
];
...
...
@@ -788,7 +813,7 @@ static CGFloat itemMargin = 5;
photoPreviewVc
.
models
=
self
->
_models
;
[
self
pushPhotoPrevireViewController
:
photoPreviewVc
];
}
else
{
[
tzImagePickerVc
.
selectedModels
addObject
:
assetModel
];
[
tzImagePickerVc
addSelectedModel
:
assetModel
];
[
self
doneButtonClick
];
}
return
;
...
...
@@ -799,7 +824,7 @@ static CGFloat itemMargin = 5;
// 不能多选视频的情况下,不选中拍摄的视频
}
else
{
assetModel
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
assetModel
];
[
tzImagePickerVc
addSelectedModel
:
assetModel
];
[
self
refreshBottomToolBarStatus
];
}
}
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
View file @
452babd8
...
...
@@ -23,6 +23,7 @@
UIView
*
_naviBar
;
UIButton
*
_backButton
;
UIButton
*
_selectButton
;
UILabel
*
_indexLabel
;
UIView
*
_toolBar
;
UIButton
*
_doneButton
;
...
...
@@ -98,12 +99,21 @@
[
_backButton
addTarget
:
self
action
:
@selector
(
backButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
_selectButton
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectZero
];
[
_selectButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoDefImageName
]
forState
:
UIControlStateNormal
];
[
_selectButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoSelImageName
]
forState
:
UIControlStateSelected
];
[
_selectButton
setImage
:
tzImagePickerVc
.
photoDefImage
forState
:
UIControlStateNormal
];
[
_selectButton
setImage
:
tzImagePickerVc
.
photoSelImage
forState
:
UIControlStateSelected
];
_selectButton
.
imageView
.
clipsToBounds
=
YES
;
_selectButton
.
imageEdgeInsets
=
UIEdgeInsetsMake
(
10
,
0
,
10
,
0
);
_selectButton
.
imageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
[
_selectButton
addTarget
:
self
action
:
@selector
(
select
:
)
forControlEvents
:
UIControlEventTouchUpInside
];
_selectButton
.
hidden
=
!
tzImagePickerVc
.
showSelectBtn
;
_indexLabel
=
[[
UILabel
alloc
]
init
];
_indexLabel
.
font
=
[
UIFont
systemFontOfSize
:
14
];
_indexLabel
.
textColor
=
[
UIColor
whiteColor
];
_indexLabel
.
textAlignment
=
NSTextAlignmentCenter
;
[
_naviBar
addSubview
:
_selectButton
];
[
_naviBar
addSubview
:
_indexLabel
];
[
_naviBar
addSubview
:
_backButton
];
[
self
.
view
addSubview
:
_naviBar
];
}
...
...
@@ -124,8 +134,8 @@
[
_originalPhotoButton
setTitle
:
_tzImagePickerVc
.
fullImageBtnTitleStr
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setTitleColor
:[
UIColor
lightGrayColor
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setTitleColor
:[
UIColor
whiteColor
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:
[
UIImage
imageNamedFromMyBundle
:
_tzImagePickerVc
.
photoPreviewOriginDefImageName
]
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:
[
UIImage
imageNamedFromMyBundle
:
_tzImagePickerVc
.
photoOriginSelImageName
]
forState
:
UIControlStateSelected
];
[
_originalPhotoButton
setImage
:
_tzImagePickerVc
.
photoPreviewOriginDefImage
forState
:
UIControlStateNormal
];
[
_originalPhotoButton
setImage
:
_tzImagePickerVc
.
photoOriginSelImage
forState
:
UIControlStateSelected
];
_originalPhotoLabel
=
[[
UILabel
alloc
]
init
];
_originalPhotoLabel
.
textAlignment
=
NSTextAlignmentLeft
;
...
...
@@ -141,8 +151,10 @@
[
_doneButton
setTitle
:
_tzImagePickerVc
.
doneBtnTitleStr
forState
:
UIControlStateNormal
];
[
_doneButton
setTitleColor
:
_tzImagePickerVc
.
oKButtonTitleColorNormal
forState
:
UIControlStateNormal
];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:
[
UIImage
imageNamedFromMyBundle
:
_tzImagePickerVc
.
photoNumberIconImageName
]
];
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:
_tzImagePickerVc
.
photoNumberIconImage
];
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberImageView
.
clipsToBounds
=
YES
;
_numberImageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
_numberImageView
.
hidden
=
_tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLabel
=
[[
UILabel
alloc
]
init
];
...
...
@@ -223,7 +235,8 @@
CGFloat
naviBarHeight
=
statusBarHeight
+
_tzImagePickerVc
.
navigationBar
.
tz_height
;
_naviBar
.
frame
=
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
naviBarHeight
);
_backButton
.
frame
=
CGRectMake
(
10
,
10
+
statusBarHeightInterval
,
44
,
44
);
_selectButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
54
,
10
+
statusBarHeightInterval
,
42
,
42
);
_selectButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
,
10
+
statusBarHeightInterval
,
44
,
44
);
_indexLabel
.
frame
=
_selectButton
.
frame
;
_layout
.
itemSize
=
CGSizeMake
(
self
.
view
.
tz_width
+
20
,
self
.
view
.
tz_height
);
_layout
.
minimumInteritemSpacing
=
0
;
...
...
@@ -248,7 +261,7 @@
}
[
_doneButton
sizeToFit
];
_doneButton
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
_doneButton
.
tz_width
-
12
,
0
,
_doneButton
.
tz_width
,
44
);
_numberImageView
.
frame
=
CGRectMake
(
_doneButton
.
tz_left
-
30
-
2
,
7
,
30
,
30
);
_numberImageView
.
frame
=
CGRectMake
(
_doneButton
.
tz_left
-
24
-
5
,
10
,
24
,
24
);
_numberLabel
.
frame
=
_numberImageView
.
frame
;
[
self
configCropView
];
...
...
@@ -273,7 +286,7 @@
return
;
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制
}
else
{
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
_tzImagePickerVc
addSelectedModel
:
model
];
if
(
self
.
photos
)
{
[
_tzImagePickerVc
.
selectedAssets
addObject
:
_assetsTemp
[
_currentIndex
]];
[
self
.
photos
addObject
:
_photosTemp
[
_currentIndex
]];
...
...
@@ -291,11 +304,11 @@
for
(
NSInteger
i
=
0
;
i
<
selectedModelsTmp
.
count
;
i
++
)
{
TZAssetModel
*
model
=
selectedModelsTmp
[
i
];
if
([
model
isEqual
:
model_item
])
{
[
_tzImagePickerVc
.
selectedModels
removeObjectAtIndex
:
i
];
[
_tzImagePickerVc
removeSelectedModel
:
model
];
// [_tzImagePickerVc.selectedModels removeObjectAtIndex:i];
break
;
}
}
// [_tzImagePickerVc.selectedModels removeObject:model_item];
if
(
self
.
photos
)
{
// 1.6.7版本更新:防止有多个一样的asset,一次性被移除了
NSArray
*
selectedAssetsTmp
=
[
NSArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
...
...
@@ -343,7 +356,7 @@
// 如果没有选中过照片 点击确定时选中当前预览的照片
if
(
_tzImagePickerVc
.
selectedModels
.
count
==
0
&&
_tzImagePickerVc
.
minImagesCount
<=
0
)
{
TZAssetModel
*
model
=
_models
[
_currentIndex
];
[
_tzImagePickerVc
.
selectedModels
addObject
:
model
];
[
_tzImagePickerVc
addSelectedModel
:
model
];
}
if
(
_tzImagePickerVc
.
allowCrop
)
{
// 裁剪状态
NSIndexPath
*
indexPath
=
[
NSIndexPath
indexPathForItem
:
_currentIndex
inSection
:
0
];
...
...
@@ -475,6 +488,15 @@
TZImagePickerController
*
_tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
TZAssetModel
*
model
=
_models
[
_currentIndex
];
_selectButton
.
selected
=
model
.
isSelected
;
[
self
refreshSelectButtonImageViewContentMode
];
if
(
_selectButton
.
isSelected
&&
_tzImagePickerVc
.
showSelectedIndex
)
{
NSString
*
assetId
=
[[
TZImageManager
manager
]
getAssetIdentifier
:
model
.
asset
];
NSString
*
index
=
[
NSString
stringWithFormat
:
@"%zd"
,
[
_tzImagePickerVc
.
selectedAssetIds
indexOfObject
:
assetId
]
+
1
];
_indexLabel
.
text
=
index
;
_indexLabel
.
hidden
=
NO
;
}
else
{
_indexLabel
.
hidden
=
YES
;
}
_numberLabel
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_tzImagePickerVc
.
selectedModels
.
count
];
_numberImageView
.
hidden
=
(
_tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
||
_isCropImage
);
_numberLabel
.
hidden
=
(
_tzImagePickerVc
.
selectedModels
.
count
<=
0
||
_isHideNaviBar
||
_isCropImage
);
...
...
@@ -508,6 +530,16 @@
}
}
-
(
void
)
refreshSelectButtonImageViewContentMode
{
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
if
(
self
->
_selectButton
.
imageView
.
image
.
size
.
width
<=
27
)
{
self
->
_selectButton
.
imageView
.
contentMode
=
UIViewContentModeCenter
;
}
else
{
self
->
_selectButton
.
imageView
.
contentMode
=
UIViewContentModeScaleAspectFit
;
}
});
}
-
(
void
)
showPhotoBytes
{
[[
TZImageManager
manager
]
getPhotosBytesWithArray
:@[
_models
[
_currentIndex
]]
completion
:
^
(
NSString
*
totalBytes
)
{
self
->
_originalPhotoLabel
.
text
=
[
NSString
stringWithFormat
:
@"(%@)"
,
totalBytes
];
...
...
TZImagePickerController/ViewController.m
View file @
452babd8
...
...
@@ -47,6 +47,7 @@
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
allowCropSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
needCircleCropSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
allowPickingMuitlpleVideoSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
showSelectedIndexSwitch
;
@end
@implementation
ViewController
...
...
@@ -106,7 +107,7 @@
-
(
void
)
viewDidLayoutSubviews
{
[
super
viewDidLayoutSubviews
];
NSInteger
contentSizeH
=
1
3
*
35
+
20
;
NSInteger
contentSizeH
=
1
4
*
35
+
20
;
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
01
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
self
.
scrollView
.
contentSize
=
CGSizeMake
(
0
,
contentSizeH
+
5
);
});
...
...
@@ -182,6 +183,7 @@
imagePickerVc
.
allowPickingGif
=
self
.
allowPickingGifSwitch
.
isOn
;
imagePickerVc
.
allowPickingOriginalPhoto
=
self
.
allowPickingOriginalPhotoSwitch
.
isOn
;
imagePickerVc
.
allowPickingMultipleVideo
=
self
.
allowPickingMuitlpleVideoSwitch
.
isOn
;
imagePickerVc
.
showSelectedIndex
=
self
.
showSelectedIndexSwitch
.
isOn
;
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
self
->
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
...
...
@@ -248,6 +250,7 @@
// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
// imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];
// imagePickerVc.navigationBar.translucent = NO;
imagePickerVc
.
iconThemeColor
=
[
UIColor
redColor
];
// 3. Set allow picking video & photo & originalPhoto or not
// 3. 设置是否可以选择视频/图片/原图
...
...
@@ -298,6 +301,9 @@
// imagePickerVc.isStatusBarDefault = NO;
imagePickerVc
.
statusBarStyle
=
UIStatusBarStyleLightContent
;
// 设置是否显示图片序号
imagePickerVc
.
showSelectedIndex
=
self
.
showSelectedIndexSwitch
.
isOn
;
// 设置首选语言 / Set preferred language
// imagePickerVc.preferredLanguage = @"zh-Hans";
...
...
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