Skip to content

Commit 51f4019

Browse files
committed
Merge branch 1and2papa#180 into 'master'
2 parents b7cc5ce + 0dfaa77 commit 51f4019

12 files changed

+247
-59
lines changed

CTAssetsPickerController.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'CTAssetsPickerController'
3-
spec.version = '3.2.0'
3+
spec.version = '3.2.4'
44
spec.summary = 'iOS control that allows picking multiple photos and videos from user\'s photo library.'
55

66
spec.description = <<-DESC
@@ -15,9 +15,9 @@ Pod::Spec.new do |spec|
1515
spec.license = { :type => 'MIT', :file => 'LICENSE' }
1616
spec.author = { 'Clement T' => '[email protected]' }
1717
spec.social_media_url = 'https://twitter.com/chiunam'
18-
spec.platform = :ios, '8.3'
19-
spec.ios.deployment_target = '8.3'
20-
spec.source = { :git => 'https://github.com/chiunam/CTAssetsPickerController.git', :tag => 'v3.2.0' }
18+
spec.platform = :ios, '8.0'
19+
spec.ios.deployment_target = '8.0'
20+
spec.source = { :git => 'https://github.com/chiunam/CTAssetsPickerController.git', :tag => 'v3.2.4' }
2121
spec.public_header_files = 'CTAssetsPickerController/*.h'
2222
spec.source_files = 'CTAssetsPickerController/**/*.{h,m}'
2323
spec.resource_bundles = { 'CTAssetsPickerController' => ['CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/*/*.png', 'CTAssetsPickerController/Resources/*.lproj'] }

CTAssetsPickerController/CTAssetCollectionViewController.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ - (void)viewWillAppear:(BOOL)animated
9292
[self selectDefaultAssetCollection];
9393
}
9494

95-
- (void)viewWillDisappear:(BOOL)animated
96-
{
97-
[super viewWillDisappear:animated];
98-
[self resetTitle];
99-
}
100-
10195
- (void)dealloc
10296
{
10397
[self unregisterChangeObserver];
@@ -492,6 +486,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
492486
PHAssetCollection *collection = self.assetCollections[indexPath.row];
493487

494488
CTAssetsGridViewController *vc = [CTAssetsGridViewController new];
489+
vc.title = self.picker.selectedAssetsString ? : collection.localizedTitle;
495490
vc.assetCollection = collection;
496491
vc.delegate = self;
497492

@@ -510,6 +505,7 @@ - (void)showDefaultAssetCollection
510505
if (self.defaultAssetCollection && !self.didShowDefaultAssetCollection)
511506
{
512507
CTAssetsGridViewController *vc = [CTAssetsGridViewController new];
508+
vc.title = self.picker.selectedAssetsString ? : self.defaultAssetCollection.localizedTitle;
513509
vc.assetCollection = self.defaultAssetCollection;
514510
vc.delegate = self;
515511

CTAssetsPickerController/CTAssetsGridViewController.m

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ of this software and associated documentation files (the "Software"), to deal
4343

4444

4545

46+
4647
NSString * const CTAssetsGridViewCellIdentifier = @"CTAssetsGridViewCellIdentifier";
4748
NSString * const CTAssetsGridViewFooterIdentifier = @"CTAssetsGridViewFooterIdentifier";
4849

@@ -311,29 +312,66 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance
311312
}
312313
else
313314
{
314-
// if we have incremental diffs, tell the collection view to animate insertions and deletions
315-
[collectionView performBatchUpdates:^{
316-
NSIndexSet *removedIndexes = [changeDetails removedIndexes];
317-
if ([removedIndexes count])
318-
{
319-
[collectionView deleteItemsAtIndexPaths:[removedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0]];
320-
}
321-
322-
NSIndexSet *insertedIndexes = [changeDetails insertedIndexes];
323-
if ([insertedIndexes count])
324-
{
325-
[collectionView insertItemsAtIndexPaths:[insertedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0]];
326-
}
327-
328-
NSIndexSet *changedIndexes = [changeDetails changedIndexes];
329-
if ([changedIndexes count])
315+
NSArray *removedPaths;
316+
NSArray *insertedPaths;
317+
NSArray *changedPaths;
318+
319+
NSIndexSet *removedIndexes = [changeDetails removedIndexes];
320+
removedPaths = [removedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0];
321+
322+
NSIndexSet *insertedIndexes = [changeDetails insertedIndexes];
323+
insertedPaths = [insertedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0];
324+
325+
NSIndexSet *changedIndexes = [changeDetails changedIndexes];
326+
changedPaths = [changedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0];
327+
328+
BOOL shouldReload = NO;
329+
330+
if (changedPaths != nil && removedPaths != nil)
331+
{
332+
for (NSIndexPath *changedPath in changedPaths)
330333
{
331-
[collectionView reloadItemsAtIndexPaths:[changedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0] ];
334+
if ([removedPaths containsObject:changedPath])
335+
{
336+
shouldReload = YES;
337+
break;
338+
}
332339
}
333-
} completion:^(BOOL finished){
334-
if (finished)
335-
[self resetCachedAssetImages];
336-
}];
340+
}
341+
342+
if (removedPaths.lastObject && ((NSIndexPath *)removedPaths.lastObject).item >= self.fetchResult.count)
343+
{
344+
shouldReload = YES;
345+
}
346+
347+
if (shouldReload)
348+
{
349+
[collectionView reloadData];
350+
351+
}
352+
else
353+
{
354+
// if we have incremental diffs, tell the collection view to animate insertions and deletions
355+
[collectionView performBatchUpdates:^{
356+
if ([removedPaths count])
357+
{
358+
[collectionView deleteItemsAtIndexPaths:[removedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0]];
359+
}
360+
361+
if ([insertedPaths count])
362+
{
363+
[collectionView insertItemsAtIndexPaths:[insertedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0]];
364+
}
365+
366+
if ([changedPaths count])
367+
{
368+
[collectionView reloadItemsAtIndexPaths:[changedIndexes ctassetsPickerIndexPathsFromIndexesWithSection:0] ];
369+
}
370+
} completion:^(BOOL finished){
371+
if (finished)
372+
[self resetCachedAssetImages];
373+
}];
374+
}
337375
}
338376

339377
[self.footer bind:self.fetchResult];

CTAssetsPickerController/CTAssetsGridViewLayout.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (instancetype)initWithContentSize:(CGSize)contentSize traitCollection:(UITrait
3434
{
3535
CGFloat scale = traits.displayScale;
3636
NSInteger numberOfColumns = [self numberOfColumnsForTraitCollection:traits];
37-
CGFloat onePixel = 1 / scale;
37+
CGFloat onePixel = (scale == 3.0) ? (2.0 / scale) : (1.0 / scale);
3838

3939
// spacing is as small as possible
4040
self.minimumInteritemSpacing = onePixel;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
3+
MIT License (MIT)
4+
5+
Copyright (c) 2015 bawn
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
*/
26+
27+
#import <UIKit/UIKit.h>
28+
29+
@interface CTAssetsNavigationController : UINavigationController
30+
31+
@end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
3+
MIT License (MIT)
4+
5+
Copyright (c) 2015 bawn
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
*/
26+
27+
#import "CTAssetsNavigationController.h"
28+
29+
30+
31+
@interface CTAssetsNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
32+
33+
@end
34+
35+
@implementation CTAssetsNavigationController
36+
37+
- (void)viewDidLoad
38+
{
39+
[super viewDidLoad];
40+
__weak CTAssetsNavigationController<UIGestureRecognizerDelegate> *weakSelf = self;
41+
42+
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
43+
{
44+
self.interactivePopGestureRecognizer.delegate = weakSelf;
45+
46+
self.delegate = weakSelf;
47+
}
48+
49+
}
50+
51+
- (void)didReceiveMemoryWarning {
52+
[super didReceiveMemoryWarning];
53+
// Dispose of any resources that can be recreated.
54+
}
55+
56+
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
57+
{
58+
59+
if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] && animated == YES )
60+
{
61+
self.interactivePopGestureRecognizer.enabled = NO;
62+
}
63+
64+
[super pushViewController:viewController animated:animated];
65+
66+
}
67+
68+
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
69+
{
70+
if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] && animated == YES )
71+
{
72+
self.interactivePopGestureRecognizer.enabled = NO;
73+
}
74+
75+
return [super popToRootViewControllerAnimated:animated];
76+
77+
}
78+
79+
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
80+
{
81+
if( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] )
82+
{
83+
self.interactivePopGestureRecognizer.enabled = NO;
84+
}
85+
86+
return [super popToViewController:viewController animated:animated];
87+
88+
}
89+
90+
#pragma mark UINavigationControllerDelegate
91+
92+
- (void)navigationController:(UINavigationController *)navigationController
93+
didShowViewController:(UIViewController *)viewController
94+
animated:(BOOL)animate
95+
{
96+
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
97+
{
98+
self.interactivePopGestureRecognizer.enabled = YES;
99+
}
100+
}
101+
102+
103+
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
104+
{
105+
106+
if ( gestureRecognizer == self.interactivePopGestureRecognizer )
107+
{
108+
if ( self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0] )
109+
{
110+
return NO;
111+
}
112+
}
113+
114+
return YES;
115+
}
116+
117+
118+
@end
119+

CTAssetsPickerController/CTAssetsPageView.m

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ - (void)setupViews
6363

6464
- (void)setPageBackgroundColor:(UIColor *)backgroundColor
6565
{
66-
_pageBackgroundColor = (backgroundColor) ? backgroundColor : CTAssetsPageViewPageBackgroundColor;
66+
UIColor *color = (backgroundColor) ? backgroundColor : CTAssetsPageViewPageBackgroundColor;
67+
_pageBackgroundColor = color;
68+
self.backgroundColor = color;
6769
}
68-
- (void)setFullscreenBackgroundColor:(UIColor *)backgroundColor
70+
71+
- (void)setFullscreenBackgroundColor:(UIColor *)fullscreenBackgroundColor
6972
{
70-
_fullscreenBackgroundColor = (backgroundColor) ? backgroundColor : CTAssetsPageViewFullscreenBackgroundColor;
73+
UIColor *color = (fullscreenBackgroundColor) ? fullscreenBackgroundColor : CTAssetsPageViewFullscreenBackgroundColor;
74+
_fullscreenBackgroundColor = color;
7175
}
7276

7377

CTAssetsPickerController/CTAssetsPickerController.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ of this software and associated documentation files (the "Software"), to deal
3737
#import "NSBundle+CTAssetsPickerController.h"
3838
#import "UIImage+CTAssetsPickerController.h"
3939
#import "NSNumberFormatter+CTAssetsPickerController.h"
40-
40+
#import "CTAssetsNavigationController.h"
4141

4242

4343

@@ -157,7 +157,7 @@ - (void)initAssetCollectionSubtypes
157157
- (void)initThumbnailRequestOptions
158158
{
159159
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
160-
options.resizeMode = PHImageRequestOptionsResizeModeExact;
160+
options.resizeMode = PHImageRequestOptionsResizeModeFast;
161161
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
162162

163163
_thumbnailRequestOptions = options;
@@ -249,13 +249,10 @@ - (void)setupEmptyViewController
249249
- (void)setupSplitViewController
250250
{
251251
CTAssetCollectionViewController *vc = [CTAssetCollectionViewController new];
252-
UINavigationController *master = [[UINavigationController alloc] initWithRootViewController:vc];
252+
CTAssetsNavigationController *master = [[CTAssetsNavigationController alloc] initWithRootViewController:vc];
253253
UINavigationController *detail = [self emptyNavigationController];
254254
UISplitViewController *svc = [UISplitViewController new];
255255

256-
master.interactivePopGestureRecognizer.enabled = YES;
257-
master.interactivePopGestureRecognizer.delegate = nil;
258-
259256
svc.delegate = self;
260257
svc.viewControllers = @[master, detail];
261258
svc.presentsWithGesture = NO;

0 commit comments

Comments
 (0)