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
c856c007
Commit
c856c007
authored
Aug 20, 2016
by
tanzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增单选模式,设置maxImagesCount为1即可
parent
20be4328
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
12 deletions
+60
-12
TZImagePickerController/Base.lproj/Main.storyboard
TZImagePickerController/Base.lproj/Main.storyboard
+20
-2
TZImagePickerController/TZImagePickerController/TZAssetCell.h
...agePickerController/TZImagePickerController/TZAssetCell.h
+2
-0
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+6
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+14
-4
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
...roller/TZImagePickerController/TZPhotoPreviewController.m
+3
-2
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+15
-4
No files found.
TZImagePickerController/Base.lproj/Main.storyboard
View file @
c856c007
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"10117"
systemVersion=
"15
F34
"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
initialViewController=
"BYZ-38-t0r"
>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"10117"
systemVersion=
"15
G31
"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
initialViewController=
"BYZ-38-t0r"
>
<dependencies>
<deployment
identifier=
"iOS"
/>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"10085"
/>
...
...
@@ -18,7 +18,7 @@
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<subviews>
<view
contentMode=
"scaleToFill"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"4Ae-5T-gEc"
userLabel=
"TopContentView"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"320"
height=
"3
00
"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"320"
height=
"3
44
"
/>
<subviews>
<view
contentMode=
"scaleToFill"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"obE-hs-XLa"
userLabel=
"View1"
>
<rect
key=
"frame"
x=
"0.0"
y=
"20"
width=
"320"
height=
"44"
/>
...
...
@@ -125,6 +125,23 @@
</subviews>
<color
key=
"backgroundColor"
white=
"1"
alpha=
"1"
colorSpace=
"calibratedWhite"
/>
</view>
<view
contentMode=
"scaleToFill"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"PA2-zk-4Ey"
userLabel=
"View7"
>
<rect
key=
"frame"
x=
"0.0"
y=
"284"
width=
"320"
height=
"44"
/>
<subviews>
<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=
"rK3-1U-kcW"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
<textField
opaque=
"NO"
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
fixedFrame=
"YES"
contentHorizontalAlignment=
"left"
contentVerticalAlignment=
"center"
text=
"9"
borderStyle=
"roundedRect"
textAlignment=
"center"
minimumFontSize=
"17"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"37K-cO-hgf"
>
<rect
key=
"frame"
x=
"220"
y=
"7"
width=
"80"
height=
"30"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"14"
/>
<textInputTraits
key=
"textInputTraits"
keyboardType=
"numberPad"
/>
</textField>
</subviews>
<color
key=
"backgroundColor"
white=
"1"
alpha=
"1"
colorSpace=
"calibratedWhite"
/>
</view>
</subviews>
</view>
</subviews>
...
...
@@ -135,6 +152,7 @@
<outlet
property=
"allowPickingImageSwitch"
destination=
"iRQ-aE-1KG"
id=
"V7a-u6-cLv"
/>
<outlet
property=
"allowPickingOriginalPhotoSwitch"
destination=
"4L3-Da-pcd"
id=
"KFm-Zl-dpD"
/>
<outlet
property=
"allowPickingVideoSwitch"
destination=
"a58-aK-ZB0"
id=
"9Ti-hW-QRj"
/>
<outlet
property=
"maxCountTF"
destination=
"37K-cO-hgf"
id=
"776-gE-tea"
/>
<outlet
property=
"showSheetSwitch"
destination=
"uHt-bT-lBZ"
id=
"NxK-wM-ivE"
/>
<outlet
property=
"showTakePhotoBtnSwitch"
destination=
"jpa-B9-8n6"
id=
"lh8-2O-IWS"
/>
<outlet
property=
"sortAscendingSwitch"
destination=
"Rbt-bh-r0x"
id=
"WEA-Vq-uSg"
/>
...
...
TZImagePickerController/TZImagePickerController/TZAssetCell.h
View file @
c856c007
...
...
@@ -29,6 +29,8 @@ typedef enum : NSUInteger {
@property
(
nonatomic
,
copy
)
NSString
*
photoSelImageName
;
@property
(
nonatomic
,
copy
)
NSString
*
photoDefImageName
;
@property
(
nonatomic
,
assign
)
NSInteger
maxImagesCount
;
@end
...
...
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
c856c007
...
...
@@ -69,6 +69,12 @@
}
}
-
(
void
)
setMaxImagesCount
:(
NSInteger
)
maxImagesCount
{
_maxImagesCount
=
maxImagesCount
;
self
.
selectPhotoButton
.
hidden
=
maxImagesCount
==
1
;
self
.
selectImageView
.
hidden
=
maxImagesCount
==
1
;
}
-
(
void
)
setType
:(
TZAssetCellType
)
type
{
_type
=
type
;
if
(
type
==
TZAssetCellTypePhoto
||
type
==
TZAssetCellTypeLivePhoto
)
{
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
c856c007
...
...
@@ -107,6 +107,8 @@ static CGSize AssetGridThumbnailSize;
}
-
(
void
)
configCollectionView
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
CGFloat
margin
=
4
;
CGFloat
itemWH
=
(
self
.
view
.
tz_width
-
2
*
margin
-
4
)
/
4
-
margin
;
...
...
@@ -115,7 +117,8 @@ static CGSize AssetGridThumbnailSize;
layout
.
minimumLineSpacing
=
margin
;
CGFloat
top
=
margin
+
44
;
if
(
iOS7Later
)
top
+=
20
;
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
margin
,
top
,
self
.
view
.
tz_width
-
2
*
margin
,
self
.
view
.
tz_height
-
50
-
top
)
collectionViewLayout
:
layout
];
CGFloat
collectionViewHeight
=
tzImagePickerVc
.
maxImagesCount
>
1
?
self
.
view
.
tz_height
-
50
-
top
:
self
.
view
.
tz_height
-
top
;
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
margin
,
top
,
self
.
view
.
tz_width
-
2
*
margin
,
collectionViewHeight
)
collectionViewLayout
:
layout
];
_collectionView
.
backgroundColor
=
[
UIColor
whiteColor
];
_collectionView
.
dataSource
=
self
;
_collectionView
.
delegate
=
self
;
...
...
@@ -123,7 +126,6 @@ static CGSize AssetGridThumbnailSize;
if
(
iOS7Later
)
_collectionView
.
contentInset
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
2
);
_collectionView
.
scrollIndicatorInsets
=
UIEdgeInsetsMake
(
0
,
0
,
0
,
-
2
);
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
_showTakePhotoBtn
&&
tzImagePickerVc
.
allowTakePicture
)
{
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
((
_model
.
count
+
4
)
/
4
)
*
self
.
view
.
tz_width
);
}
else
{
...
...
@@ -155,6 +157,8 @@ static CGSize AssetGridThumbnailSize;
-
(
void
)
configBottomToolBar
{
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
maxImagesCount
<=
1
)
return
;
UIView
*
bottomToolBar
=
[[
UIView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
self
.
view
.
tz_height
-
50
,
self
.
view
.
tz_width
,
50
)];
CGFloat
rgb
=
253
/
255
.
0
;
bottomToolBar
.
backgroundColor
=
[
UIColor
colorWithRed
:
rgb
green
:
rgb
blue
:
rgb
alpha
:
1
.
0
];
...
...
@@ -163,6 +167,7 @@ static CGSize AssetGridThumbnailSize;
CGFloat
previewWidth
=
[
previewText
boundingRectWithSize
:
CGSizeMake
(
CGFLOAT_MAX
,
CGFLOAT_MAX
)
options
:
NSStringDrawingUsesFontLeading
attributes
:
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
16
]}
context
:
nil
].
size
.
width
;
_previewButton
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
_previewButton
.
frame
=
CGRectMake
(
10
,
3
,
previewWidth
+
2
,
44
);
_previewButton
.
tz_width
=
tzImagePickerVc
.
maxImagesCount
<=
1
?
0
:
previewWidth
+
2
;
[
_previewButton
addTarget
:
self
action
:
@selector
(
previewButtonClick
)
forControlEvents
:
UIControlEventTouchUpInside
];
_previewButton
.
titleLabel
.
font
=
[
UIFont
systemFontOfSize
:
16
];
[
_previewButton
setTitle
:
previewText
forState
:
UIControlStateNormal
];
...
...
@@ -208,7 +213,6 @@ static CGSize AssetGridThumbnailSize;
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoNumberIconImageName
]];
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
12
,
26
,
26
);
_numberImageView
.
hidden
=
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberLable
=
[[
UILabel
alloc
]
init
];
...
...
@@ -217,7 +221,6 @@ static CGSize AssetGridThumbnailSize;
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
tzImagePickerVc
.
selectedModels
.
count
];
_numberLable
.
hidden
=
tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
UIView
*
divide
=
[[
UIView
alloc
]
init
];
...
...
@@ -336,6 +339,7 @@ static CGSize AssetGridThumbnailSize;
model
=
_models
[
indexPath
.
row
-
1
];
}
cell
.
model
=
model
;
cell
.
maxImagesCount
=
tzImagePickerVc
.
maxImagesCount
;
__weak
typeof
(
cell
)
weakCell
=
cell
;
__weak
typeof
(
self
)
weakSelf
=
self
;
...
...
@@ -560,6 +564,12 @@ static CGSize AssetGridThumbnailSize;
assetModel
=
[
models
firstObject
];
[
_models
insertObject
:
assetModel
atIndex
:
0
];
}
if
(
tzImagePickerVc
.
maxImagesCount
<=
1
)
{
[
tzImagePickerVc
.
selectedModels
addObject
:
assetModel
];
[
self
okButtonClick
];
return
;
}
if
(
tzImagePickerVc
.
selectedModels
.
count
<
tzImagePickerVc
.
maxImagesCount
)
{
assetModel
.
isSelected
=
YES
;
[
tzImagePickerVc
.
selectedModels
addObject
:
assetModel
];
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
View file @
c856c007
...
...
@@ -83,6 +83,7 @@
[
_selectButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoDefImageName
]
forState
:
UIControlStateNormal
];
[
_selectButton
setImage
:[
UIImage
imageNamedFromMyBundle
:
tzImagePickerVc
.
photoSelImageName
]
forState
:
UIControlStateSelected
];
[
_selectButton
addTarget
:
self
action
:
@selector
(
select
:
)
forControlEvents
:
UIControlEventTouchUpInside
];
_selectButton
.
hidden
=
tzImagePickerVc
.
maxImagesCount
==
1
;
[
_naviBar
addSubview
:
_selectButton
];
[
_naviBar
addSubview
:
_backButton
];
...
...
@@ -131,7 +132,7 @@
_numberImageView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamedFromMyBundle
:
_tzImagePickerVc
.
photoNumberIconImageName
]];
_numberImageView
.
backgroundColor
=
[
UIColor
clearColor
];
_numberImageView
.
frame
=
CGRectMake
(
self
.
view
.
tz_width
-
56
-
24
,
9
,
26
,
26
);
_numberImageView
.
hidden
=
_tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberImageView
.
hidden
=
_tzImagePickerVc
.
selectedModels
.
count
<=
1
;
_numberLable
=
[[
UILabel
alloc
]
init
];
_numberLable
.
frame
=
_numberImageView
.
frame
;
...
...
@@ -139,7 +140,7 @@
_numberLable
.
textColor
=
[
UIColor
whiteColor
];
_numberLable
.
textAlignment
=
NSTextAlignmentCenter
;
_numberLable
.
text
=
[
NSString
stringWithFormat
:
@"%zd"
,
_tzImagePickerVc
.
selectedModels
.
count
];
_numberLable
.
hidden
=
_tzImagePickerVc
.
selectedModels
.
count
<=
0
;
_numberLable
.
hidden
=
_tzImagePickerVc
.
selectedModels
.
count
<=
1
;
_numberLable
.
backgroundColor
=
[
UIColor
clearColor
];
[
_originalPhotoButton
addSubview
:
_originalPhotoLable
];
...
...
TZImagePickerController/ViewController.m
View file @
c856c007
...
...
@@ -34,6 +34,7 @@
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
allowPickingImageSwitch
;
///< 允许选择图片
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
allowPickingOriginalPhotoSwitch
;
///< 允许选择原图
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
showSheetSwitch
;
///< 显示一个sheet,把拍照按钮放在外面
@property
(
weak
,
nonatomic
)
IBOutlet
UITextField
*
maxCountTF
;
///< 照片最大可选张数,设置为1即为单选模式
@end
@implementation
ViewController
...
...
@@ -77,13 +78,14 @@
_layout
.
itemSize
=
CGSizeMake
(
_itemWH
,
_itemWH
);
_layout
.
minimumInteritemSpacing
=
_margin
;
_layout
.
minimumLineSpacing
=
_margin
;
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
3
00
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
300
)
collectionViewLayout
:
_layout
];
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
3
44
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
-
344
)
collectionViewLayout
:
_layout
];
CGFloat
rgb
=
244
/
255
.
0
;
_collectionView
.
alwaysBounceVertical
=
YES
;
_collectionView
.
backgroundColor
=
[
UIColor
colorWithRed
:
rgb
green
:
rgb
blue
:
rgb
alpha
:
1
.
0
];
_collectionView
.
contentInset
=
UIEdgeInsetsMake
(
4
,
4
,
4
,
4
);
_collectionView
.
dataSource
=
self
;
_collectionView
.
delegate
=
self
;
_collectionView
.
keyboardDismissMode
=
UIScrollViewKeyboardDismissModeOnDrag
;
[
self
.
view
addSubview
:
_collectionView
];
[
_collectionView
registerClass
:[
TZTestCell
class
]
forCellWithReuseIdentifier
:
@"TZTestCell"
];
}
...
...
@@ -170,13 +172,18 @@
#pragma mark - TZImagePickerController
-
(
void
)
pushImagePickerController
{
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
9
delegate
:
self
];
if
(
self
.
maxCountTF
.
text
.
integerValue
<=
0
)
{
return
;
}
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithMaxImagesCount
:
self
.
maxCountTF
.
text
.
integerValue
delegate
:
self
];
#pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
if
(
self
.
maxCountTF
.
text
.
integerValue
>
1
)
{
// 1.如果你需要将拍照按钮放在外面,不要传这个参数
imagePickerVc
.
selectedAssets
=
_selectedAssets
;
// optional, 可选的
}
imagePickerVc
.
allowTakePicture
=
self
.
showTakePhotoBtnSwitch
.
isOn
;
// 在内部显示拍照按钮
// 2. Set the appearance
...
...
@@ -382,4 +389,8 @@
}
}
-
(
void
)
touchesBegan
:(
NSSet
<
UITouch
*>
*
)
touches
withEvent
:(
UIEvent
*
)
event
{
[
self
.
view
endEditing
:
YES
];
}
@end
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