Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Added a new property for single selection image size. #19

Merged
merged 3 commits into from
Sep 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
*/
@property (nonatomic, readonly) YMSPhotoPickerTheme *theme;

/**
* @brief Use this property to customize the returned item type for single selection. YES for UIImage, NO for PHAsset. Default value is YES.
*/
@property (nonatomic, assign) BOOL shouldReturnImageForSingleSelection;

@end

/**
Expand Down
47 changes: 27 additions & 20 deletions YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ - (instancetype)init
if (self) {
self.selectedPhotos = [NSMutableArray array];
self.numberOfPhotoToSelect = 1;
self.shouldReturnImageForSingleSelection = YES;
}
return self;
}
Expand Down Expand Up @@ -214,26 +215,32 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
[self yms_presentCameraCaptureViewWithDelegate:self];
}
else if (NO == self.allowsMultipleSelection) {

PHFetchResult *fetchResult = self.currentCollectionItem[@"assets"];
PHAsset *asset = fetchResult[indexPath.item-1];

// Prepare the options to pass when fetching the live photo.
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;
options.resizeMode = PHImageRequestOptionsResizeModeExact;

CGSize targetSize = CGSizeMake(asset.pixelWidth, asset.pixelHeight);

[self.imageManager requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
if (image && [self.delegate respondsToSelector:@selector(photoPickerViewController:didFinishPickingImage:)]) {
[self.delegate photoPickerViewController:self didFinishPickingImage:[self yms_orientationNormalizedImage:image]];
}
else {
[self dismiss:nil];
}
}];
if (NO == self.shouldReturnImageForSingleSelection) {
PHFetchResult *fetchResult = self.currentCollectionItem[@"assets"];
PHAsset *asset = fetchResult[indexPath.item-1];
[self.selectedPhotos addObject:asset];
[self finishPickingPhotos:nil];
} else {
PHFetchResult *fetchResult = self.currentCollectionItem[@"assets"];
PHAsset *asset = fetchResult[indexPath.item-1];

// Prepare the options to pass when fetching the live photo.
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;
options.resizeMode = PHImageRequestOptionsResizeModeExact;

CGSize targetSize = CGSizeMake(asset.pixelWidth, asset.pixelHeight);

[self.imageManager requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
if (image && [self.delegate respondsToSelector:@selector(photoPickerViewController:didFinishPickingImage:)]) {
[self.delegate photoPickerViewController:self didFinishPickingImage:[self yms_orientationNormalizedImage:image]];
}
else {
[self dismiss:nil];
}
}];
}
}
else {
PHFetchResult *fetchResult = self.currentCollectionItem[@"assets"];
Expand Down