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
16080c96
Commit
16080c96
authored
Aug 12, 2016
by
banchichen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
预览时给照片添加20像素宽的间距
parent
ae034fd8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
67 deletions
+20
-67
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+5
-22
TZImagePickerController/TZImagePickerController/TZPhotoPreviewCell.m
...erController/TZImagePickerController/TZPhotoPreviewCell.m
+6
-6
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
...roller/TZImagePickerController/TZPhotoPreviewController.m
+9
-39
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
16080c96
...
@@ -78,8 +78,7 @@ static CGFloat TZScreenScale;
...
@@ -78,8 +78,7 @@ static CGFloat TZScreenScale;
PHAssetMediaTypeVideo
];
PHAssetMediaTypeVideo
];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:self.sortAscendingByModificationDate]];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:self.sortAscendingByModificationDate]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeAlbumRegular
options
:
nil
];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeSmartAlbumUserLibrary
options
:
nil
];
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"所有照片"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"All Photos"
])
{
if
([
collection
.
localizedTitle
isEqualToString
:
@"Camera Roll"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"相机胶卷"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"所有照片"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"All Photos"
])
{
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
...
@@ -89,7 +88,6 @@ static CGFloat TZScreenScale;
...
@@ -89,7 +88,6 @@ static CGFloat TZScreenScale;
}
}
}
}
}
else
{
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[
self
.
assetLibrary
enumerateGroupsWithTypes
:
ALAssetsGroupAll
usingBlock
:
^
(
ALAssetsGroup
*
group
,
BOOL
*
stop
)
{
[
self
.
assetLibrary
enumerateGroupsWithTypes
:
ALAssetsGroupAll
usingBlock
:
^
(
ALAssetsGroup
*
group
,
BOOL
*
stop
)
{
...
@@ -112,16 +110,11 @@ static CGFloat TZScreenScale;
...
@@ -112,16 +110,11 @@ static CGFloat TZScreenScale;
if
(
!
allowPickingVideo
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeImage
];
if
(
!
allowPickingVideo
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeImage
];
if
(
!
allowPickingImage
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
if
(
!
allowPickingImage
)
option
.
predicate
=
[
NSPredicate
predicateWithFormat
:
@"mediaType == %ld"
,
PHAssetMediaTypeVideo
];
PHAssetMediaTypeVideo
];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:self.sortAscendingByModificationDate]];
// option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:self.sortAscendingByModificationDate]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
option
.
sortDescriptors
=
@[[
NSSortDescriptor
sortDescriptorWithKey
:
@"modificationDate"
ascending
:
self
.
sortAscendingByModificationDate
]];
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
PHAssetCollectionSubtypeAlbumRegular
options
:
nil
];
PHFetchResult
*
topLevelUserCollections
=
[
PHCollectionList
fetchTopLevelUserCollectionsWithOptions
:
nil
];
PHAssetCollectionSubtype
smartAlbumSubtype
=
PHAssetCollectionSubtypeSmartAlbumUserLibrary
|
PHAssetCollectionSubtypeSmartAlbumRecentlyAdded
|
PHAssetCollectionSubtypeSmartAlbumVideos
;
// For iOS 9, We need to show ScreenShots Album && SelfPortraits Album
if
(
iOS9Later
)
{
smartAlbumSubtype
=
PHAssetCollectionSubtypeSmartAlbumUserLibrary
|
PHAssetCollectionSubtypeSmartAlbumRecentlyAdded
|
PHAssetCollectionSubtypeSmartAlbumScreenshots
|
PHAssetCollectionSubtypeSmartAlbumSelfPortraits
|
PHAssetCollectionSubtypeSmartAlbumVideos
;
}
PHFetchResult
*
smartAlbums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeSmartAlbum
subtype
:
smartAlbumSubtype
options
:
nil
];
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
for
(
PHAssetCollection
*
collection
in
smartAlbums
)
{
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
if
(
fetchResult
.
count
<
1
)
continue
;
if
(
fetchResult
.
count
<
1
)
continue
;
...
@@ -132,21 +125,11 @@ static CGFloat TZScreenScale;
...
@@ -132,21 +125,11 @@ static CGFloat TZScreenScale;
[
albumArr
addObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]];
[
albumArr
addObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]];
}
}
}
}
for
(
PHAssetCollection
*
collection
in
topLevelUserCollections
)
{
PHFetchResult
*
albums
=
[
PHAssetCollection
fetchAssetCollectionsWithType
:
PHAssetCollectionTypeAlbum
subtype
:
PHAssetCollectionSubtypeAlbumRegular
|
PHAssetCollectionSubtypeAlbumSyncedAlbum
options
:
nil
];
for
(
PHAssetCollection
*
collection
in
albums
)
{
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
PHFetchResult
*
fetchResult
=
[
PHAsset
fetchAssetsInAssetCollection
:
collection
options
:
option
];
if
(
fetchResult
.
count
<
1
)
continue
;
if
(
fetchResult
.
count
<
1
)
continue
;
if
([
collection
.
localizedTitle
isEqualToString
:
@"My Photo Stream"
]
||
[
collection
.
localizedTitle
isEqualToString
:
@"我的照片流"
])
{
if
(
albumArr
.
count
)
{
[
albumArr
insertObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]
atIndex
:
1
];
}
else
{
[
albumArr
addObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]];
[
albumArr
addObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]];
}
}
}
else
{
[
albumArr
addObject
:[
self
modelWithResult
:
fetchResult
name
:
collection
.
localizedTitle
]];
}
}
if
(
completion
&&
albumArr
.
count
>
0
)
completion
(
albumArr
);
if
(
completion
&&
albumArr
.
count
>
0
)
completion
(
albumArr
);
}
else
{
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic push
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewCell.m
View file @
16080c96
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
if
(
self
)
{
if
(
self
)
{
self
.
backgroundColor
=
[
UIColor
blackColor
];
self
.
backgroundColor
=
[
UIColor
blackColor
];
_scrollView
=
[[
UIScrollView
alloc
]
init
];
_scrollView
=
[[
UIScrollView
alloc
]
init
];
_scrollView
.
frame
=
CGRectMake
(
0
,
0
,
self
.
tz_width
,
self
.
tz_height
);
_scrollView
.
frame
=
CGRectMake
(
10
,
0
,
self
.
tz_width
-
20
,
self
.
tz_height
);
_scrollView
.
bouncesZoom
=
YES
;
_scrollView
.
bouncesZoom
=
YES
;
_scrollView
.
maximumZoomScale
=
2
.
5
;
_scrollView
.
maximumZoomScale
=
2
.
5
;
_scrollView
.
minimumZoomScale
=
1
.
0
;
_scrollView
.
minimumZoomScale
=
1
.
0
;
...
@@ -76,13 +76,13 @@
...
@@ -76,13 +76,13 @@
-
(
void
)
resizeSubviews
{
-
(
void
)
resizeSubviews
{
_imageContainerView
.
tz_origin
=
CGPointZero
;
_imageContainerView
.
tz_origin
=
CGPointZero
;
_imageContainerView
.
tz_width
=
self
.
tz_width
;
_imageContainerView
.
tz_width
=
self
.
scrollView
.
tz_width
;
UIImage
*
image
=
_imageView
.
image
;
UIImage
*
image
=
_imageView
.
image
;
if
(
image
.
size
.
height
/
image
.
size
.
width
>
self
.
tz_height
/
self
.
tz_width
)
{
if
(
image
.
size
.
height
/
image
.
size
.
width
>
self
.
tz_height
/
self
.
scrollView
.
tz_width
)
{
_imageContainerView
.
tz_height
=
floor
(
image
.
size
.
height
/
(
image
.
size
.
width
/
self
.
tz_width
));
_imageContainerView
.
tz_height
=
floor
(
image
.
size
.
height
/
(
image
.
size
.
width
/
self
.
scrollView
.
tz_width
));
}
else
{
}
else
{
CGFloat
height
=
image
.
size
.
height
/
image
.
size
.
width
*
self
.
tz_width
;
CGFloat
height
=
image
.
size
.
height
/
image
.
size
.
width
*
self
.
scrollView
.
tz_width
;
if
(
height
<
1
||
isnan
(
height
))
height
=
self
.
tz_height
;
if
(
height
<
1
||
isnan
(
height
))
height
=
self
.
tz_height
;
height
=
floor
(
height
);
height
=
floor
(
height
);
_imageContainerView
.
tz_height
=
height
;
_imageContainerView
.
tz_height
=
height
;
...
@@ -91,7 +91,7 @@
...
@@ -91,7 +91,7 @@
if
(
_imageContainerView
.
tz_height
>
self
.
tz_height
&&
_imageContainerView
.
tz_height
-
self
.
tz_height
<=
1
)
{
if
(
_imageContainerView
.
tz_height
>
self
.
tz_height
&&
_imageContainerView
.
tz_height
-
self
.
tz_height
<=
1
)
{
_imageContainerView
.
tz_height
=
self
.
tz_height
;
_imageContainerView
.
tz_height
=
self
.
tz_height
;
}
}
_scrollView
.
contentSize
=
CGSizeMake
(
self
.
tz_width
,
MAX
(
_imageContainerView
.
tz_height
,
self
.
tz_height
));
_scrollView
.
contentSize
=
CGSizeMake
(
self
.
scrollView
.
tz_width
,
MAX
(
_imageContainerView
.
tz_height
,
self
.
tz_height
));
[
_scrollView
scrollRectToVisible
:
self
.
bounds
animated
:
NO
];
[
_scrollView
scrollRectToVisible
:
self
.
bounds
animated
:
NO
];
_scrollView
.
alwaysBounceVertical
=
_imageContainerView
.
tz_height
<=
self
.
tz_height
?
NO
:
YES
;
_scrollView
.
alwaysBounceVertical
=
_imageContainerView
.
tz_height
<=
self
.
tz_height
?
NO
:
YES
;
_imageView
.
frame
=
_imageContainerView
.
bounds
;
_imageView
.
frame
=
_imageContainerView
.
bounds
;
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m
View file @
16080c96
...
@@ -29,8 +29,6 @@
...
@@ -29,8 +29,6 @@
UILabel
*
_numberLable
;
UILabel
*
_numberLable
;
UIButton
*
_originalPhotoButton
;
UIButton
*
_originalPhotoButton
;
UILabel
*
_originalPhotoLable
;
UILabel
*
_originalPhotoLable
;
CGFloat
_minimumLineSpacing
;
}
}
@end
@end
...
@@ -45,7 +43,6 @@
...
@@ -45,7 +43,6 @@
_assetsTemp
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
_assetsTemp
=
[
NSMutableArray
arrayWithArray
:
_tzImagePickerVc
.
selectedAssets
];
self
.
isSelectOriginalPhoto
=
_tzImagePickerVc
.
isSelectOriginalPhoto
;
self
.
isSelectOriginalPhoto
=
_tzImagePickerVc
.
isSelectOriginalPhoto
;
}
}
_minimumLineSpacing
=
20
;
[
self
configCollectionView
];
[
self
configCollectionView
];
[
self
configCustomNaviBar
];
[
self
configCustomNaviBar
];
[
self
configBottomToolBar
];
[
self
configBottomToolBar
];
...
@@ -60,7 +57,7 @@
...
@@ -60,7 +57,7 @@
[
super
viewWillAppear
:
animated
];
[
super
viewWillAppear
:
animated
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
iOS7Later
)
[
UIApplication
sharedApplication
].
statusBarHidden
=
YES
;
if
(
_currentIndex
)
[
_collectionView
setContentOffset
:
CGPointMake
((
self
.
view
.
tz_width
+
_minimumLineSpacing
)
*
_currentIndex
,
0
)
animated
:
NO
];
if
(
_currentIndex
)
[
_collectionView
setContentOffset
:
CGPointMake
((
self
.
view
.
tz_width
+
20
)
*
_currentIndex
,
0
)
animated
:
NO
];
[
self
refreshNaviBarAndBottomBarState
];
[
self
refreshNaviBarAndBottomBarState
];
}
}
...
@@ -153,17 +150,18 @@
...
@@ -153,17 +150,18 @@
-
(
void
)
configCollectionView
{
-
(
void
)
configCollectionView
{
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
layout
.
scrollDirection
=
UICollectionViewScrollDirectionHorizontal
;
layout
.
scrollDirection
=
UICollectionViewScrollDirectionHorizontal
;
layout
.
itemSize
=
CGSizeMake
(
self
.
view
.
tz_width
,
self
.
view
.
tz_height
);
layout
.
itemSize
=
CGSizeMake
(
self
.
view
.
tz_width
+
20
,
self
.
view
.
tz_height
);
layout
.
minimumInteritemSpacing
=
0
;
layout
.
minimumInteritemSpacing
=
0
;
layout
.
minimumLineSpacing
=
_minimumLineSpacing
;
layout
.
minimumLineSpacing
=
0
;
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
view
.
tz_width
,
self
.
view
.
tz_height
)
collectionViewLayout
:
layout
];
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
CGRectMake
(
-
10
,
0
,
self
.
view
.
tz_width
+
20
,
self
.
view
.
tz_height
)
collectionViewLayout
:
layout
];
_collectionView
.
backgroundColor
=
[
UIColor
blackColor
];
_collectionView
.
backgroundColor
=
[
UIColor
blackColor
];
_collectionView
.
dataSource
=
self
;
_collectionView
.
dataSource
=
self
;
_collectionView
.
delegate
=
self
;
_collectionView
.
delegate
=
self
;
_collectionView
.
pagingEnabled
=
YES
;
_collectionView
.
scrollsToTop
=
NO
;
_collectionView
.
scrollsToTop
=
NO
;
_collectionView
.
showsHorizontalScrollIndicator
=
NO
;
_collectionView
.
showsHorizontalScrollIndicator
=
NO
;
_collectionView
.
contentOffset
=
CGPointMake
(
0
,
0
);
_collectionView
.
contentOffset
=
CGPointMake
(
0
,
0
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
view
.
tz_width
*
_models
.
count
,
self
.
view
.
tz_height
);
_collectionView
.
contentSize
=
CGSizeMake
(
self
.
models
.
count
*
(
self
.
view
.
tz_width
+
20
),
0
);
[
self
.
view
addSubview
:
_collectionView
];
[
self
.
view
addSubview
:
_collectionView
];
[
_collectionView
registerClass
:[
TZPhotoPreviewCell
class
]
forCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
];
[
_collectionView
registerClass
:[
TZPhotoPreviewCell
class
]
forCellWithReuseIdentifier
:
@"TZPhotoPreviewCell"
];
}
}
...
@@ -248,13 +246,10 @@
...
@@ -248,13 +246,10 @@
#pragma mark - UIScrollViewDelegate
#pragma mark - UIScrollViewDelegate
-
(
void
)
scrollViewDidScroll
:(
UIScrollView
*
)
scrollView
{
-
(
void
)
scrollViewDidScroll
:(
UIScrollView
*
)
scrollView
{
CGPoint
offSet
=
scrollView
.
contentOffset
;
CGFloat
offSetWidth
=
scrollView
.
contentOffset
.
x
;
CGFloat
offSetWidth
=
offSet
.
x
;
offSetWidth
=
offSetWidth
+
((
self
.
view
.
tz_width
+
20
)
*
0
.
5
);
if
((
offSetWidth
+
((
self
.
view
.
tz_width
+
_minimumLineSpacing
)
*
0
.
5
))
<
scrollView
.
contentSize
.
width
+
_minimumLineSpacing
)
{
offSetWidth
=
offSetWidth
+
((
self
.
view
.
tz_width
+
_minimumLineSpacing
)
*
0
.
5
);
}
NSInteger
currentIndex
=
offSetWidth
/
(
self
.
view
.
tz_width
+
_minimumLineSpacing
);
NSInteger
currentIndex
=
offSetWidth
/
(
self
.
view
.
tz_width
+
20
);
if
(
_currentIndex
!=
currentIndex
)
{
if
(
_currentIndex
!=
currentIndex
)
{
_currentIndex
=
currentIndex
;
_currentIndex
=
currentIndex
;
...
@@ -298,31 +293,6 @@
...
@@ -298,31 +293,6 @@
}
}
}
}
-
(
void
)
scrollViewWillEndDragging
:(
UIScrollView
*
)
scrollView
withVelocity
:(
CGPoint
)
velocity
targetContentOffset
:(
inout
CGPoint
*
)
targetContentOffset
{
CGFloat
contentOffsetX
=
scrollView
.
contentOffset
.
x
;
NSInteger
MAX_INDEX
=
(
scrollView
.
contentSize
.
width
+
_minimumLineSpacing
)
/
(
self
.
view
.
tz_width
+
_minimumLineSpacing
)
-
1
;
NSInteger
MIN_INDEX
=
0
;
NSInteger
index
=
contentOffsetX
/
(
self
.
view
.
tz_width
+
_minimumLineSpacing
);
if
(
velocity
.
x
>
0
.
4
&&
contentOffsetX
<
(
*
targetContentOffset
).
x
)
{
index
=
index
+
1
;
}
else
if
(
velocity
.
x
<
-
0
.
4
&&
contentOffsetX
>
(
*
targetContentOffset
).
x
)
{
index
=
index
;
}
else
if
(
contentOffsetX
>
(
index
+
0
.
5
)
*
(
self
.
view
.
tz_width
+
_minimumLineSpacing
))
{
index
=
index
+
1
;
}
if
(
index
>
MAX_INDEX
)
index
=
MAX_INDEX
;
if
(
index
<
MIN_INDEX
)
index
=
MIN_INDEX
;
CGPoint
newTargetContentOffset
=
CGPointMake
(
index
*
(
self
.
view
.
tz_width
+
_minimumLineSpacing
),
0
);
*
targetContentOffset
=
CGPointMake
(
scrollView
.
contentOffset
.
x
,
0
);
[
scrollView
setContentOffset
:
newTargetContentOffset
animated
:
YES
];
}
#pragma mark - Private Method
#pragma mark - Private Method
-
(
void
)
refreshNaviBarAndBottomBarState
{
-
(
void
)
refreshNaviBarAndBottomBarState
{
...
...
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