Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for iPad in iPhone mode #224

Merged
merged 2 commits into from Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CTAssetsPickerController/CTAssetCollectionViewController.m
Expand Up @@ -32,6 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTAssetsGridViewController.h"
#import "PHAssetCollection+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "PHImageManager+CTAssetsPickerController.h"
#import "NSBundle+CTAssetsPickerController.h"


Expand Down Expand Up @@ -440,7 +441,7 @@ - (void)requestThumbnailsForCell:(CTAssetCollectionViewCell *)cell assetCollecti
if (index < assets.count)
{
PHAsset *asset = assets[index];
[self.imageManager requestImageForAsset:asset
[self.imageManager ctassetsPickerRequestImageForAsset:asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFill
options:self.picker.thumbnailRequestOptions
Expand Down
3 changes: 2 additions & 1 deletion CTAssetsPickerController/CTAssetItemViewController.m
Expand Up @@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTAssetScrollView.h"
#import "NSBundle+CTAssetsPickerController.h"
#import "PHAsset+CTAssetsPickerController.h"
#import "PHImageManager+CTAssetsPickerController.h"



Expand Down Expand Up @@ -185,7 +186,7 @@ - (void)requestAssetImage
PHImageRequestOptions *options = [self imageRequestOptions];

self.imageRequestID =
[self.imageManager requestImageForAsset:self.asset
[self.imageManager ctassetsPickerRequestImageForAsset:self.asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFit
options:options
Expand Down
3 changes: 2 additions & 1 deletion CTAssetsPickerController/CTAssetsGridViewController.m
Expand Up @@ -39,6 +39,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "UICollectionView+CTAssetsPickerController.h"
#import "NSIndexSet+CTAssetsPickerController.h"
#import "NSBundle+CTAssetsPickerController.h"
#import "PHImageManager+CTAssetsPickerController.h"



Expand Down Expand Up @@ -693,7 +694,7 @@ - (void)requestThumbnailForCell:(CTAssetsGridViewCell *)cell targetSize:(CGSize)
NSInteger tag = cell.tag + 1;
cell.tag = tag;

[self.imageManager requestImageForAsset:asset
[self.imageManager ctassetsPickerRequestImageForAsset:asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFill
options:self.picker.thumbnailRequestOptions
Expand Down
@@ -0,0 +1,15 @@
//
// PHImageManager+CTSupport.h
// CTAssetsPickerDemo
//
// Created by Korben Allen Rusek on 4/7/16.
// Copyright © 2016 Clement T. All rights reserved.
//

#import <Photos/Photos.h>

@interface PHImageManager (CTAssetsPickerController)

- (PHImageRequestID)ctassetsPickerRequestImageForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:( PHImageRequestOptions *)options resultHandler:(void (^)(UIImage * result, NSDictionary * info))resultHandler;

@end
@@ -0,0 +1,40 @@
//
// PHImageManager+CTSupport.m
// CTAssetsPickerDemo
//
// Created by Korben Allen Rusek on 4/7/16.
// Copyright © 2016 Clement T. All rights reserved.
//

#import "PHImageManager+CTAssetsPickerController.h"

@implementation PHImageManager (CTAssetsPickerController)

+ (BOOL)ctassetsPickerNeedsiPadSupportSize {
return [(NSString*)[UIDevice currentDevice].model hasPrefix:@"iPad"] && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad == false;
}

+ (CGSize)ctassetsPickerSizeForSize:(CGSize)size withMinimumDimension:(CGFloat)dimension {
if (size.width >= dimension && size.height >= dimension) return size;
if (size.width <= 0 || size.height <= 0) return size;

CGFloat width, height;
if (size.width < size.height) {
width = 500;
height = size.height/size.width*width;
} else {
height = 500;
width = size.width/size.height*height;
}
return CGSizeMake(width, height);
}

- (PHImageRequestID)ctassetsPickerRequestImageForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:( PHImageRequestOptions *)options resultHandler:(void (^)(UIImage * result, NSDictionary * info))resultHandler {
CGSize size = targetSize;
if ([[self class] ctassetsPickerNeedsiPadSupportSize]) {
size = [[self class] ctassetsPickerSizeForSize:targetSize withMinimumDimension:500];
}
return [self requestImageForAsset:asset targetSize:size contentMode:contentMode options:options resultHandler:resultHandler];
}

@end
8 changes: 8 additions & 0 deletions CTAssetsPickerDemo.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */; };
363F8D0A685BF86C60D06D49 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */; };
AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; };
AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; };
Expand All @@ -32,6 +33,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0B3423A61CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PHImageManager+CTAssetsPickerController.h"; sourceTree = "<group>"; };
0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PHImageManager+CTAssetsPickerController.m"; sourceTree = "<group>"; };
408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
A741BBA31B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/CTAssetsPicker.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -360,6 +363,8 @@
AD30D7F71AAE9D0400C79E3D /* NSNumberFormatter+CTAssetsPickerController.m */,
ADD965FE1AAD5780002A26A2 /* NSDateFormatter+CTAssetsPickerController.h */,
ADD965FF1AAD5780002A26A2 /* NSDateFormatter+CTAssetsPickerController.m */,
0B3423A61CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.h */,
0B3423A71CB6E9C7003509E0 /* PHImageManager+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 */,
0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */,
AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */,
ADA0730D1B4625AA009FB7C7 /* CTUITweaksViewController.m in Sources */,
AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */,
Expand Down Expand Up @@ -700,6 +706,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
Expand All @@ -714,6 +721,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
Expand Down
3 changes: 2 additions & 1 deletion CTAssetsPickerDemo/Examples/CTBasicViewController.m
Expand Up @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
*/

#import "CTBasicViewController.h"
#import "PHImageManager+CTAssetsPickerController.h"


#define tableViewRowHeight 80.0f
Expand Down Expand Up @@ -138,7 +139,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
CGFloat scale = UIScreen.mainScreen.scale;
CGSize targetSize = CGSizeMake(tableViewRowHeight * scale, tableViewRowHeight * scale);

[manager requestImageForAsset:asset
[manager ctassetsPickerRequestImageForAsset:asset
targetSize:targetSize
contentMode:PHImageContentModeAspectFill
options:self.requestOptions
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
@@ -1,5 +1,5 @@
PODS:
- CTAssetsPickerController (3.2.4):
- CTAssetsPickerController (3.3.1):
- PureLayout (~> 3.0.0)
- PureLayout (3.0.1)

Expand All @@ -11,7 +11,7 @@ EXTERNAL SOURCES:
:path: .

SPEC CHECKSUMS:
CTAssetsPickerController: bc7264c9bc40064b7de4a66bf9948c2c5ce3f355
CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed
PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb

COCOAPODS: 0.39.0