Commit 16080c96 authored by banchichen's avatar banchichen

预览时给照片添加20像素宽的间距

parent ae034fd8
......@@ -78,8 +78,7 @@ static CGFloat TZScreenScale;
PHAssetMediaTypeVideo];
// 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];
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
for (PHAssetCollection *collection in smartAlbums) {
if ([collection.localizedTitle isEqualToString:@"Camera Roll"] || [collection.localizedTitle isEqualToString:@"相机胶卷"] || [collection.localizedTitle isEqualToString:@"所有照片"] || [collection.localizedTitle isEqualToString:@"All Photos"]) {
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option];
......@@ -89,7 +88,6 @@ static CGFloat TZScreenScale;
}
}
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
......@@ -112,16 +110,11 @@ 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: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) {
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option];
if (fetchResult.count < 1) continue;
......@@ -132,20 +125,10 @@ static CGFloat TZScreenScale;
[albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]];
}
}
PHFetchResult *albums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular | PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
for (PHAssetCollection *collection in albums) {
for (PHAssetCollection *collection in topLevelUserCollections) {
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option];
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]];
}
} else {
[albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]];
}
[albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]];
}
if (completion && albumArr.count > 0) completion(albumArr);
} else {
......
......@@ -26,7 +26,7 @@
if (self) {
self.backgroundColor = [UIColor blackColor];
_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.maximumZoomScale = 2.5;
_scrollView.minimumZoomScale = 1.0;
......@@ -76,13 +76,13 @@
- (void)resizeSubviews {
_imageContainerView.tz_origin = CGPointZero;
_imageContainerView.tz_width = self.tz_width;
_imageContainerView.tz_width = self.scrollView.tz_width;
UIImage *image = _imageView.image;
if (image.size.height / image.size.width > self.tz_height / self.tz_width) {
_imageContainerView.tz_height = floor(image.size.height / (image.size.width / 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.scrollView.tz_width));
} 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;
height = floor(height);
_imageContainerView.tz_height = height;
......@@ -91,7 +91,7 @@
if (_imageContainerView.tz_height > self.tz_height && _imageContainerView.tz_height - self.tz_height <= 1) {
_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.alwaysBounceVertical = _imageContainerView.tz_height <= self.tz_height ? NO : YES;
_imageView.frame = _imageContainerView.bounds;
......
......@@ -29,8 +29,6 @@
UILabel *_numberLable;
UIButton *_originalPhotoButton;
UILabel *_originalPhotoLable;
CGFloat _minimumLineSpacing;
}
@end
......@@ -45,7 +43,6 @@
_assetsTemp = [NSMutableArray arrayWithArray:_tzImagePickerVc.selectedAssets];
self.isSelectOriginalPhoto = _tzImagePickerVc.isSelectOriginalPhoto;
}
_minimumLineSpacing = 20;
[self configCollectionView];
[self configCustomNaviBar];
[self configBottomToolBar];
......@@ -60,7 +57,7 @@
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden: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];
}
......@@ -153,17 +150,18 @@
- (void)configCollectionView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
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.minimumLineSpacing = _minimumLineSpacing;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.tz_width , self.view.tz_height) collectionViewLayout:layout];
layout.minimumLineSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(-10, 0, self.view.tz_width + 20, self.view.tz_height) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor blackColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.pagingEnabled = YES;
_collectionView.scrollsToTop = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
_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];
[_collectionView registerClass:[TZPhotoPreviewCell class] forCellWithReuseIdentifier:@"TZPhotoPreviewCell"];
}
......@@ -248,13 +246,10 @@
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint offSet = scrollView.contentOffset;
CGFloat offSetWidth = offSet.x;
if ((offSetWidth + ((self.view.tz_width + _minimumLineSpacing) * 0.5)) < scrollView.contentSize.width + _minimumLineSpacing) {
offSetWidth = offSetWidth + ((self.view.tz_width + _minimumLineSpacing) * 0.5);
}
CGFloat offSetWidth = scrollView.contentOffset.x;
offSetWidth = offSetWidth + ((self.view.tz_width + 20) * 0.5);
NSInteger currentIndex = offSetWidth / (self.view.tz_width + _minimumLineSpacing);
NSInteger currentIndex = offSetWidth / (self.view.tz_width + 20);
if (_currentIndex != currentIndex) {
_currentIndex = currentIndex;
......@@ -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
- (void)refreshNaviBarAndBottomBarState {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment