Skip to content

Commit

Permalink
Merge pull request #188 from chrisze/master
Browse files Browse the repository at this point in the history
#189 Fix memory issue and visual bugs
  • Loading branch information
1and2papa committed Jan 11, 2016
2 parents 4a8623d + b341c62 commit f43df23
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 8 deletions.
14 changes: 8 additions & 6 deletions CTAssetsPickerController/CTAssetCollectionViewController.m
Expand Up @@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "PHAssetCollection+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "NSBundle+CTAssetsPickerController.h"
#import "UIViewController+CTAssetsPickerController.h"



Expand Down Expand Up @@ -92,12 +93,6 @@ - (void)viewWillAppear:(BOOL)animated
[self selectDefaultAssetCollection];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self resetTitle];
}

- (void)dealloc
{
[self unregisterChangeObserver];
Expand Down Expand Up @@ -339,6 +334,11 @@ - (void)selectedAssetsChanged:(NSNotification *)notification
[self updateButton:selectedAssets];
}

- (void)setTitle:(NSString *)title
{
self.ctnavigationItemTitle = title;
}

- (void)updateTitle:(NSArray *)selectedAssets
{
if ([self isTopViewController] && selectedAssets.count > 0)
Expand Down Expand Up @@ -492,6 +492,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
PHAssetCollection *collection = self.assetCollections[indexPath.row];

CTAssetsGridViewController *vc = [CTAssetsGridViewController new];
vc.title = self.picker.selectedAssetsString ? : collection.localizedTitle;
vc.assetCollection = collection;
vc.delegate = self;

Expand All @@ -510,6 +511,7 @@ - (void)showDefaultAssetCollection
if (self.defaultAssetCollection && !self.didShowDefaultAssetCollection)
{
CTAssetsGridViewController *vc = [CTAssetsGridViewController new];
vc.title = self.picker.selectedAssetsString ? : self.defaultAssetCollection.localizedTitle;
vc.assetCollection = self.defaultAssetCollection;
vc.delegate = self;

Expand Down
7 changes: 7 additions & 0 deletions CTAssetsPickerController/CTAssetsGridViewController.m
Expand Up @@ -39,6 +39,8 @@ of this software and associated documentation files (the "Software"), to deal
#import "UICollectionView+CTAssetsPickerController.h"
#import "NSIndexSet+CTAssetsPickerController.h"
#import "NSBundle+CTAssetsPickerController.h"
#import "UIViewController+CTAssetsPickerController.h"




Expand Down Expand Up @@ -360,6 +362,11 @@ - (void)assetsPickerSelectedAssetsDidChange:(NSNotification *)notification
[self updateButton:selectedAssets];
}

- (void)setTitle:(NSString *)title
{
self.ctnavigationItemTitle = title;
}

- (void)updateTitle:(NSArray *)selectedAssets
{
if (selectedAssets.count > 0)
Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetsGridViewLayout.m
Expand Up @@ -34,7 +34,7 @@ - (instancetype)initWithContentSize:(CGSize)contentSize traitCollection:(UITrait
{
CGFloat scale = traits.displayScale;
NSInteger numberOfColumns = [self numberOfColumnsForTraitCollection:traits];
CGFloat onePixel = 1 / scale;
CGFloat onePixel = (scale == 3.0) ? (2.0 / scale) : (1.0 / scale);

// spacing is as small as possible
self.minimumInteritemSpacing = onePixel;
Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetsPickerController.m
Expand Up @@ -157,7 +157,7 @@ - (void)initAssetCollectionSubtypes
- (void)initThumbnailRequestOptions
{
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.resizeMode = PHImageRequestOptionsResizeModeExact;
options.resizeMode = PHImageRequestOptionsResizeModeFast;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

_thumbnailRequestOptions = options;
Expand Down
@@ -0,0 +1,33 @@
/*
MIT License (MIT)
Copyright (c) 2015 Clement CN Tsang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import <UIKit/UIKit.h>

@interface UIViewController (CTAssetsPickerController)

@property (nonatomic, strong) NSString *ctnavigationItemTitle;

@end
@@ -0,0 +1,81 @@
/*
MIT License (MIT)
Copyright (c) 2015 Clement CN Tsang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#import "UIViewController+CTAssetsPickerController.h"

@implementation UIViewController (CTAssetsPickerController)

- (NSString *)ctnavigationItemTitle
{
if ([self.navigationItem.titleView isKindOfClass:[UILabel class]])
{
UILabel *titleLabel = (UILabel*)self.navigationItem.titleView;
return titleLabel.text;
}

return nil;
}

- (void)setCtnavigationItemTitle:(NSString *)title
{
UILabel *titleLabel = nil;

if ([self.navigationItem.titleView isKindOfClass:[UILabel class]])
{
titleLabel = (UILabel*)self.navigationItem.titleView;
if ([titleLabel.text isEqualToString:title]) return;
}
else
{
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1, 44)];
titleLabel.text = title;
titleLabel.font = [self cttitleFont];
titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
titleLabel.adjustsFontSizeToFitWidth = NO;
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor darkTextColor];

self.navigationItem.titleView = titleLabel;
}

titleLabel.text = title;
[titleLabel sizeToFit];
}

- (UIFont *)cttitleFont
{
NSComparisonResult result = [@"8.2" compare:[UIDevice currentDevice].systemVersion options:NSNumericSearch];

if (result == NSOrderedSame || result == NSOrderedAscending)
{
return [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
}

return [UIFont fontWithName:@"HelveticaNeue-Medium" size:17];
}

@end
6 changes: 6 additions & 0 deletions CTAssetsPickerDemo.xcodeproj/project.pbxproj
Expand Up @@ -29,6 +29,7 @@
ADFC004C1B54FF740024CBB9 /* CTLayoutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFC004B1B54FF740024CBB9 /* CTLayoutViewController.m */; };
ADFE23881B46602400E44353 /* CTProgrammaticViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFE23871B46602400E44353 /* CTProgrammaticViewController.m */; };
ADFE238B1B46868100E44353 /* CTApperanceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ADFE238A1B46868100E44353 /* CTApperanceViewController.m */; };
B0811B9F1C0D36F200342722 /* UIViewController+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = B0811B9E1C0D36F200342722 /* UIViewController+CTAssetsPickerController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -180,6 +181,8 @@
ADFE23871B46602400E44353 /* CTProgrammaticViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTProgrammaticViewController.m; sourceTree = "<group>"; };
ADFE23891B46868100E44353 /* CTApperanceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTApperanceViewController.h; sourceTree = "<group>"; };
ADFE238A1B46868100E44353 /* CTApperanceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTApperanceViewController.m; sourceTree = "<group>"; };
B0811B9D1C0D36F200342722 /* UIViewController+CTAssetsPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+CTAssetsPickerController.h"; sourceTree = "<group>"; };
B0811B9E1C0D36F200342722 /* UIViewController+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+CTAssetsPickerController.m"; sourceTree = "<group>"; };
F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FD69CDFBA7D07D903CCC8B80 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -360,6 +363,8 @@
AD30D7F71AAE9D0400C79E3D /* NSNumberFormatter+CTAssetsPickerController.m */,
ADD965FE1AAD5780002A26A2 /* NSDateFormatter+CTAssetsPickerController.h */,
ADD965FF1AAD5780002A26A2 /* NSDateFormatter+CTAssetsPickerController.m */,
B0811B9D1C0D36F200342722 /* UIViewController+CTAssetsPickerController.h */,
B0811B9E1C0D36F200342722 /* UIViewController+CTAssetsPickerController.m */,
);
path = Categories;
sourceTree = "<group>";
Expand Down Expand Up @@ -538,6 +543,7 @@
ADA073101B462C98009FB7C7 /* CTLastWeekViewController.m in Sources */,
AD4B06C81B428EEF00D99C5A /* CTiCloudAlbumsViewController.m in Sources */,
AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */,
B0811B9F1C0D36F200342722 /* UIViewController+CTAssetsPickerController.m in Sources */,
AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */,
ADA0730D1B4625AA009FB7C7 /* CTUITweaksViewController.m in Sources */,
AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */,
Expand Down

0 comments on commit f43df23

Please sign in to comment.