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
b53c5298
Commit
b53c5298
authored
Jun 21, 2016
by
tanzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增视频预览功能
parent
5acab807
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
22 deletions
+81
-22
.DS_Store
.DS_Store
+0
-0
TZImagePickerController/Base.lproj/Main.storyboard
TZImagePickerController/Base.lproj/Main.storyboard
+9
-6
TZImagePickerController/TZImagePickerController/.DS_Store
TZImagePickerController/TZImagePickerController/.DS_Store
+0
-0
TZImagePickerController/TZImagePickerController/TZAssetCell.m
...agePickerController/TZImagePickerController/TZAssetCell.m
+1
-0
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
...troller/TZImagePickerController/TZImagePickerController.m
+1
-1
TZImagePickerController/TZImagePickerController/TZVideoPlayerController.m
...troller/TZImagePickerController/TZVideoPlayerController.m
+5
-1
TZImagePickerController/TZTestCell.h
TZImagePickerController/TZTestCell.h
+2
-0
TZImagePickerController/TZTestCell.m
TZImagePickerController/TZTestCell.m
+22
-0
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+41
-14
No files found.
.DS_Store
View file @
b53c5298
No preview for this file type
TZImagePickerController/Base.lproj/Main.storyboard
View file @
b53c5298
...
...
@@ -32,7 +32,7 @@
<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=
"R92-Zn-NWV"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
@@ -47,7 +47,7 @@
<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=
"UL3-n3-Hmt"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
@@ -58,11 +58,14 @@
<subviews>
<switch
opaque=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"750"
verticalHuggingPriority=
"750"
fixedFrame=
"YES"
contentHorizontalAlignment=
"center"
contentVerticalAlignment=
"center"
on=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"a58-aK-ZB0"
>
<rect
key=
"frame"
x=
"225"
y=
"6"
width=
"51"
height=
"31"
/>
<connections>
<action
selector=
"allowPickingVideoSwitchClick:"
destination=
"BYZ-38-t0r"
eventType=
"valueChanged"
id=
"kMA-4q-CZa"
/>
</connections>
</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=
"xCu-D3-IZg"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
@@ -80,7 +83,7 @@
<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=
"vNN-OI-9z1"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
@@ -98,7 +101,7 @@
<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=
"7mi-Lf-2N5"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
@@ -116,7 +119,7 @@
<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=
"jop-5R-ioj"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"200"
height=
"44"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"15"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor
"
/>
<color
key=
"textColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"1"
colorSpace=
"calibratedRGB
"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
...
...
TZImagePickerController/TZImagePickerController/.DS_Store
View file @
b53c5298
No preview for this file type
TZImagePickerController/TZImagePickerController/TZAssetCell.m
View file @
b53c5298
...
...
@@ -115,6 +115,7 @@
_imageView
=
imageView
;
[
self
.
contentView
bringSubviewToFront
:
_selectImageView
];
[
self
.
contentView
bringSubviewToFront
:
_bottomView
];
}
return
_imageView
;
}
...
...
TZImagePickerController/TZImagePickerController/TZImagePickerController.m
View file @
b53c5298
...
...
@@ -117,7 +117,7 @@
self
=
[
super
initWithRootViewController
:
previewVc
];
if
(
self
)
{
self
.
selectedAssets
=
[
NSMutableArray
arrayWithArray
:
selectedAssets
];
self
.
allowPickingOriginalPhoto
=
YES
;
self
.
allowPickingOriginalPhoto
=
self
.
allowPickingOriginalPhoto
;
self
.
timeout
=
15
;
self
.
photoWidth
=
828
.
0
;
self
.
maxImagesCount
=
selectedAssets
.
count
;
...
...
TZImagePickerController/TZImagePickerController/TZVideoPlayerController.m
View file @
b53c5298
...
...
@@ -117,7 +117,11 @@
if
(
imagePickerVc
.
didFinishPickingVideoHandle
)
{
imagePickerVc
.
didFinishPickingVideoHandle
(
_cover
,
_model
.
asset
);
}
if
(
self
.
navigationController
)
{
[
self
.
navigationController
dismissViewControllerAnimated
:
YES
completion
:
nil
];
}
else
{
[
self
dismissViewControllerAnimated
:
YES
completion
:
nil
];
}
}
#pragma mark - Notification Method
...
...
TZImagePickerController/TZTestCell.h
View file @
b53c5298
...
...
@@ -11,8 +11,10 @@
@interface
TZTestCell
:
UICollectionViewCell
@property
(
nonatomic
,
strong
)
UIImageView
*
imageView
;
@property
(
nonatomic
,
strong
)
UIImageView
*
videoImageView
;
@property
(
nonatomic
,
strong
)
UIButton
*
deleteBtn
;
@property
(
nonatomic
,
assign
)
NSInteger
row
;
@property
(
nonatomic
,
strong
)
id
asset
;
-
(
UIView
*
)
snapshotView
;
...
...
TZImagePickerController/TZTestCell.m
View file @
b53c5298
...
...
@@ -8,6 +8,9 @@
#import "TZTestCell.h"
#import "UIView+Layout.h"
#import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "TZImagePickerController/TZImagePickerController.h"
@implementation
TZTestCell
...
...
@@ -21,6 +24,12 @@
[
self
addSubview
:
_imageView
];
self
.
clipsToBounds
=
YES
;
_videoImageView
=
[[
UIImageView
alloc
]
init
];
_videoImageView
.
image
=
[
UIImage
imageNamedFromMyBundle
:
@"MMVideoPreviewPlay"
];
_videoImageView
.
contentMode
=
UIViewContentModeScaleAspectFill
;
_videoImageView
.
hidden
=
YES
;
[
self
addSubview
:
_videoImageView
];
_deleteBtn
=
[
UIButton
buttonWithType
:
UIButtonTypeCustom
];
[
_deleteBtn
setImage
:[
UIImage
imageNamed
:
@"photo_delete"
]
forState
:
UIControlStateNormal
];
_deleteBtn
.
frame
=
CGRectMake
(
self
.
tz_width
-
36
,
0
,
36
,
36
);
...
...
@@ -34,8 +43,21 @@
-
(
void
)
layoutSubviews
{
[
super
layoutSubviews
];
_imageView
.
frame
=
self
.
bounds
;
CGFloat
width
=
self
.
tz_width
/
3
.
0
;
_videoImageView
.
frame
=
CGRectMake
(
width
,
width
,
width
,
width
);
}
-
(
void
)
setAsset
:(
id
)
asset
{
_asset
=
asset
;
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHAsset
*
phAsset
=
asset
;
_videoImageView
.
hidden
=
phAsset
.
mediaType
!=
PHAssetMediaTypeVideo
;
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
ALAsset
*
alAsset
=
asset
;
_videoImageView
.
hidden
=
!
[[
alAsset
valueForProperty
:
ALAssetPropertyType
]
isEqualToString
:
ALAssetTypeVideo
];
}
}
-
(
void
)
setRow
:(
NSInteger
)
row
{
_row
=
row
;
_deleteBtn
.
tag
=
row
;
...
...
TZImagePickerController/ViewController.m
View file @
b53c5298
...
...
@@ -14,6 +14,7 @@
#import <Photos/Photos.h>
#import "LxGridViewFlowLayout.h"
#import "TZImageManager.h"
#import "TZVideoPlayerController.h"
@interface
ViewController
()
<
TZImagePickerControllerDelegate
,
UICollectionViewDataSource
,
UICollectionViewDelegate
>
{
NSMutableArray
*
_selectedPhotos
;
...
...
@@ -70,11 +71,13 @@
-
(
UICollectionViewCell
*
)
collectionView
:(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
TZTestCell
*
cell
=
[
collectionView
dequeueReusableCellWithReuseIdentifier
:
@"TZTestCell"
forIndexPath
:
indexPath
];
cell
.
videoImageView
.
hidden
=
YES
;
if
(
indexPath
.
row
==
_selectedPhotos
.
count
)
{
cell
.
imageView
.
image
=
[
UIImage
imageNamed
:
@"AlbumAddBtn.png"
];
cell
.
deleteBtn
.
hidden
=
YES
;
}
else
{
cell
.
imageView
.
image
=
_selectedPhotos
[
indexPath
.
row
];
cell
.
asset
=
_selectedAssets
[
indexPath
.
row
];
cell
.
deleteBtn
.
hidden
=
NO
;
}
cell
.
deleteBtn
.
tag
=
indexPath
.
row
;
...
...
@@ -85,10 +88,25 @@
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
didSelectItemAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
if
(
indexPath
.
row
==
_selectedPhotos
.
count
)
{
[
self
pushImagePickerController
];
}
else
{
// preview photos or video / 预览照片或者视频
id
asset
=
_selectedAssets
[
indexPath
.
row
];
BOOL
isVideo
=
NO
;
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHAsset
*
phAsset
=
asset
;
isVideo
=
phAsset
.
mediaType
==
PHAssetMediaTypeVideo
;
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
ALAsset
*
alAsset
=
asset
;
isVideo
=
[[
alAsset
valueForProperty
:
ALAssetPropertyType
]
isEqualToString
:
ALAssetTypeVideo
];
}
if
(
isVideo
)
{
// perview video / 预览视频
TZVideoPlayerController
*
vc
=
[[
TZVideoPlayerController
alloc
]
init
];
TZAssetModel
*
model
=
[
TZAssetModel
modelWithAsset
:
asset
type
:
TZAssetModelMediaTypeVideo
timeLength
:
@""
];
vc
.
model
=
model
;
[
self
presentViewController
:
vc
animated
:
YES
completion
:
nil
];
}
else
{
// preview photos / 预览照片
TZImagePickerController
*
imagePickerVc
=
[[
TZImagePickerController
alloc
]
initWithSelectedAssets
:
_selectedAssets
selectedPhotos
:
_selectedPhotos
index
:
indexPath
.
row
];
imagePickerVc
.
allowPickingOriginalPhoto
=
self
.
allowPickingOriginalPhotoSwitch
.
isOn
;
imagePickerVc
.
isSelectOriginalPhoto
=
_isSelectOriginalPhoto
;
// imagePickerVc.allowPickingOriginalPhoto = NO;
[
imagePickerVc
setDidFinishPickingPhotosHandle
:
^
(
NSArray
<
UIImage
*>
*
photos
,
NSArray
*
assets
,
BOOL
isSelectOriginalPhoto
)
{
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:
photos
];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:
assets
];
...
...
@@ -99,6 +117,7 @@
}];
[
self
presentViewController
:
imagePickerVc
animated
:
YES
completion
:
nil
];
}
}
}
-
(
void
)
collectionView
:(
UICollectionView
*
)
collectionView
itemAtIndexPath
:(
NSIndexPath
*
)
sourceIndexPath
didMoveToIndexPath
:(
NSIndexPath
*
)
destinationIndexPath
{
...
...
@@ -143,6 +162,7 @@
}];
[
self
presentViewController
:
imagePickerVc
animated
:
YES
completion
:
nil
];
}
...
...
@@ -184,6 +204,13 @@
if
(
!
sender
.
isOn
)
{
[
_allowPickingOriginalPhotoSwitch
setOn
:
NO
animated
:
YES
];
[
_showTakePhotoBtnSwitch
setOn
:
NO
animated
:
YES
];
[
_allowPickingVideoSwitch
setOn
:
YES
animated
:
YES
];
}
}
-
(
IBAction
)
allowPickingVideoSwitchClick
:(
UISwitch
*
)
sender
{
if
(
!
sender
.
isOn
)
{
[
_allowPickingImageSwitch
setOn
:
YES
animated
:
YES
];
}
}
...
...
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