From d2feb8c2a89830b8f441a1d018b4e42edfecaa9c Mon Sep 17 00:00:00 2001 From: metasmile Date: Fri, 7 Oct 2016 15:42:53 +0900 Subject: [PATCH 1/4] A bug fixes for UISearchBar's layout when single service was selected --- Source/Classes/Core/DZNPhotoDisplayViewController.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 3b7ebdf7..452cf551 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -97,9 +97,14 @@ - (void)loadView _selectedService = DZNFirstPhotoServiceFromPhotoServices(self.navigationController.supportedServices); NSAssert((_selectedService > 0), @"DZNPhotoPickerController requieres at least 1 supported photo service provider"); - - self.extendedLayoutIncludesOpaqueBars = YES; - self.edgesForExtendedLayout = UIRectEdgeAll; + + if(_segmentedControlTitles.count>1){ + self.extendedLayoutIncludesOpaqueBars = YES; + self.edgesForExtendedLayout = UIRectEdgeAll; + }else{ + self.extendedLayoutIncludesOpaqueBars = NO; + self.edgesForExtendedLayout = UIRectEdgeNone; + } self.automaticallyAdjustsScrollViewInsets = YES; self.definesPresentationContext = YES; From 9635deb45904826d9d50dc0eefa312a38f981e02 Mon Sep 17 00:00:00 2001 From: metasmile Date: Fri, 7 Oct 2016 16:05:32 +0900 Subject: [PATCH 2/4] add a option 'initialSelectedService' to initially select. --- Source/Classes/Core/DZNPhotoDisplayViewController.m | 8 ++++++++ Source/Classes/Core/DZNPhotoPickerController.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 452cf551..014b9d88 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -98,6 +98,14 @@ - (void)loadView _selectedService = DZNFirstPhotoServiceFromPhotoServices(self.navigationController.supportedServices); NSAssert((_selectedService > 0), @"DZNPhotoPickerController requieres at least 1 supported photo service provider"); + NSAssert(!self.navigationController.initialSelectedService || self.navigationController.initialSelectedService & self.navigationController.supportedServices, @"Provided 'initialSelectedService' doesn't support in 'supportedServices'"); + if(self.navigationController.initialSelectedService & self.navigationController.supportedServices){ + NSArray * initialSelectedService = NSArrayFromServices(self.navigationController.initialSelectedService); + NSAssert(initialSelectedService.count==1,@"Only one service flag can be assigned to initialSelectedService."); + _segmentedControlTitles = [NSSet setWithArray:[initialSelectedService arrayByAddingObjectsFromArray:_segmentedControlTitles]].allObjects; + _selectedService = self.navigationController.initialSelectedService; + } + if(_segmentedControlTitles.count>1){ self.extendedLayoutIncludesOpaqueBars = YES; self.edgesForExtendedLayout = UIRectEdgeAll; diff --git a/Source/Classes/Core/DZNPhotoPickerController.h b/Source/Classes/Core/DZNPhotoPickerController.h index 39c5232a..04a3711a 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.h +++ b/Source/Classes/Core/DZNPhotoPickerController.h @@ -29,6 +29,8 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll @property (nonatomic, assign) id delegate; /** The photo services to be supported by the controller. Default are 500px & Flickr. */ @property (nonatomic) DZNPhotoPickerControllerServices supportedServices; +/** A photo service that will initially be selected at first when controller presented. */ +@property (nonatomic) DZNPhotoPickerControllerServices initialSelectedService; /** YES if the user is allowed to edit a selected image. Default is NO. */ @property (nonatomic) BOOL allowsEditing; /** An optional string term for auto-starting the photo search, as soon as the picker is presented. */ From 691fe805cc457758a51f8fca1e99498a3d801a2d Mon Sep 17 00:00:00 2001 From: metasmile Date: Tue, 11 Oct 2016 20:59:21 +0900 Subject: [PATCH 3/4] Allows to call postMetadataUpdate by specific notifiction name --- .../Classes/Core/DZNPhotoDisplayViewController.m | 6 +++--- .../Core/DZNPhotoPickerControllerConstants.h | 1 + Source/Classes/Services/DZNPhotoMetadata.h | 2 +- Source/Classes/Services/DZNPhotoMetadata.m | 15 ++++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index 014b9d88..f250b7ed 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -432,7 +432,7 @@ - (void)resetPhotos - (void)selectedMetadata:(DZNPhotoMetadata *)metadata { if (!self.navigationController.enablePhotoDownload) { - [metadata postMetadataUpdate:nil]; + [metadata postMetadataUpdate:nil notification:DZNPhotoPickerDidFinishPickingNotification]; } else if (self.navigationController.allowsEditing) { @@ -445,7 +445,7 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata [self.navigationController pushViewController:controller animated:YES]; [controller setAcceptBlock:^(DZNPhotoEditorViewController *editor, NSDictionary *userInfo){ - [metadata postMetadataUpdate:userInfo]; + [metadata postMetadataUpdate:userInfo notification:DZNPhotoPickerDidFinishPickingNotification]; [self.navigationController popViewControllerAnimated:YES]; }]; @@ -485,7 +485,7 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished){ if (image) { NSDictionary *userInfo = @{UIImagePickerControllerOriginalImage: image}; - [metadata postMetadataUpdate:userInfo]; + [metadata postMetadataUpdate:userInfo notification:DZNPhotoPickerDidFinishPickingNotification]; } else { [self setLoadingError:error]; diff --git a/Source/Classes/Core/DZNPhotoPickerControllerConstants.h b/Source/Classes/Core/DZNPhotoPickerControllerConstants.h index 5ab4a505..acbb7486 100644 --- a/Source/Classes/Core/DZNPhotoPickerControllerConstants.h +++ b/Source/Classes/Core/DZNPhotoPickerControllerConstants.h @@ -12,6 +12,7 @@ extern NSString *const DZNPhotoPickerControllerCropMode; // An NSSt extern NSString *const DZNPhotoPickerControllerCropZoomScale; // An NSString (from 1.0 to maximum zoom scale, 2.0f) extern NSString *const DZNPhotoPickerControllerPhotoMetadata; // An NSDictionary containing metadata from a captured photo +extern NSString *const DZNPhotoPickerDidSelectPickingNotification; // The notification key used when picking a photo selected and download started. extern NSString *const DZNPhotoPickerDidFinishPickingNotification; // The notification key used when picking a photo finished. extern NSString *const DZNPhotoPickerDidFailPickingNotification; // The notification key used when picking a photo failed. diff --git a/Source/Classes/Services/DZNPhotoMetadata.h b/Source/Classes/Services/DZNPhotoMetadata.h index b5985998..9f69894c 100644 --- a/Source/Classes/Services/DZNPhotoMetadata.h +++ b/Source/Classes/Services/DZNPhotoMetadata.h @@ -75,6 +75,6 @@ @param cropMode The crop mode being used. @param photoDescription The photo metadata. */ -- (void)postMetadataUpdate:(NSDictionary *)userInfo; +- (void)postMetadataUpdate:(NSDictionary *)userInfo notification:(NSString *)name; @end diff --git a/Source/Classes/Services/DZNPhotoMetadata.m b/Source/Classes/Services/DZNPhotoMetadata.m index e09e65e6..744c2406 100644 --- a/Source/Classes/Services/DZNPhotoMetadata.m +++ b/Source/Classes/Services/DZNPhotoMetadata.m @@ -147,21 +147,22 @@ - (NSString *)description #pragma mark - Notification -- (void)postMetadataUpdate:(NSDictionary *)userInfo +- (void)postMetadataUpdate:(NSDictionary *)userInfo notification:(NSString *)name { - NSLog(@"postMetadataUpdate : %@", userInfo); - + NSLog(@"postMetadataUpdate : %@, notification: %@", userInfo, name); + NSMutableDictionary *_userInfo = [[NSMutableDictionary alloc] initWithDictionary:userInfo]; - + NSDictionary *payload = [self payload]; - + if (payload.allKeys.count > 0) { [_userInfo setObject:payload forKey:DZNPhotoPickerControllerPhotoMetadata]; } - - [[NSNotificationCenter defaultCenter] postNotificationName:DZNPhotoPickerDidFinishPickingNotification object:nil userInfo:_userInfo]; + + [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:_userInfo]; } + - (NSDictionary *)payload { NSMutableDictionary *attributes = [NSMutableDictionary new]; From 6f884c023b1e466954da33bb0cdd7253d2034a6e Mon Sep 17 00:00:00 2001 From: metasmile Date: Tue, 11 Oct 2016 21:55:14 +0900 Subject: [PATCH 4/4] add some interfaces to hide viewcontroller immediately when selects a cell. (In case of using CropModeNone) --- .../PhotoPicker/PhotoPicker/RootViewController.m | 13 ++++++++++++- .../Classes/Core/DZNPhotoDisplayViewController.m | 2 ++ Source/Classes/Core/DZNPhotoPickerController.h | 15 +++++++++++++-- Source/Classes/Core/DZNPhotoPickerController.m | 15 +++++++++++++++ .../Core/DZNPhotoPickerControllerConstants.h | 2 +- .../Core/DZNPhotoPickerControllerConstants.m | 1 + Source/Classes/Services/DZNPhotoMetadata.m | 2 +- 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Examples/PhotoPicker/PhotoPicker/RootViewController.m b/Examples/PhotoPicker/PhotoPicker/RootViewController.m index f61fb47e..32acce7d 100644 --- a/Examples/PhotoPicker/PhotoPicker/RootViewController.m +++ b/Examples/PhotoPicker/PhotoPicker/RootViewController.m @@ -132,13 +132,24 @@ - (void)presentPhotoSearch:(id)sender picker.supportedServices = DZNPhotoPickerControllerService500px | DZNPhotoPickerControllerServiceFlickr | DZNPhotoPickerControllerServiceGiphy; picker.allowsEditing = NO; picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular; +// picker.cropMode = DZNPhotoEditorViewControllerCropModeNone; picker.initialSearchTerm = @"Chile"; picker.enablePhotoDownload = YES; picker.allowAutoCompletedSearch = YES; picker.infiniteScrollingEnabled = YES; picker.title = @"Search Photos"; - + + [picker setSelectionBlock:^(DZNPhotoPickerController *picker, NSDictionary *info) { + NSLog(@"selected: %@",info); + + if(picker.cropMode == DZNPhotoEditorViewControllerCropModeNone){ + //DZNPhotoPickerController did early dismiss but processing still does proceeding + [picker popToViewController:self animated:YES]; + } + }]; + [picker setFinalizationBlock:^(DZNPhotoPickerController *picker, NSDictionary *info){ + NSLog(@"finished: %@",info); [self updateImageWithPayload:info]; [self dismissController:picker]; }]; diff --git a/Source/Classes/Core/DZNPhotoDisplayViewController.m b/Source/Classes/Core/DZNPhotoDisplayViewController.m index f250b7ed..30e98728 100644 --- a/Source/Classes/Core/DZNPhotoDisplayViewController.m +++ b/Source/Classes/Core/DZNPhotoDisplayViewController.m @@ -431,6 +431,8 @@ - (void)resetPhotos */ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata { + [metadata postMetadataUpdate:nil notification:DZNPhotoPickerDidSelectNotification]; + if (!self.navigationController.enablePhotoDownload) { [metadata postMetadataUpdate:nil notification:DZNPhotoPickerDidFinishPickingNotification]; } diff --git a/Source/Classes/Core/DZNPhotoPickerController.h b/Source/Classes/Core/DZNPhotoPickerController.h index 04a3711a..c75b5f41 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.h +++ b/Source/Classes/Core/DZNPhotoPickerController.h @@ -21,6 +21,7 @@ */ @interface DZNPhotoPickerController : UINavigationController +typedef void (^DZNPhotoPickerControllerSelectionBlock)(DZNPhotoPickerController *picker, NSDictionary *info); typedef void (^DZNPhotoPickerControllerFinalizationBlock)(DZNPhotoPickerController *picker, NSDictionary *info); typedef void (^DZNPhotoPickerControllerFailureBlock)(DZNPhotoPickerController *picker, NSError *error); typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerController *picker); @@ -43,7 +44,9 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll @property (nonatomic) DZNPhotoPickerControllerCCLicenses supportedLicenses; /** YES if the picker should download the full size photo after selecting its thumbnail, when allowsEditing is NO. Default is YES. */ @property (nonatomic) BOOL enablePhotoDownload; -/** A block to be executed whenever the user pickes a new photo. Use this block to replace delegate method photoPickerController:didFinishPickingPhotoWithInfo: */ +/** A block to be executed whenever the user selects a new photo in collection view(album view). Use this block to replace delegate method photoPickerController:didSelectPhotoWithInfo: */ +@property (nonatomic, strong) DZNPhotoPickerControllerSelectionBlock selectionBlock; +/** A block to be executed whenever the user pickes a new photo, and internal processing was finished. Use this block to replace delegate method photoPickerController:didFinishPickingPhotoWithInfo: */ @property (nonatomic, strong) DZNPhotoPickerControllerFinalizationBlock finalizationBlock; /** A block to be executed whenever an error occurs while picking a photo. Use this block to replace delegate method photoPickerController:didFailedPickingPhotoWithError: */ @property (nonatomic, strong) DZNPhotoPickerControllerFailureBlock failureBlock; @@ -91,7 +94,15 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll @required /** - Tells the delegate that the user picked a new photo. + Tells the delegate that the user selected a new photo in album view. + + @param picker The controller object managing the photo search picker interface. + @param userInfo A dictionary containing the original image. The dictionary also contains some information of selected photo. For exiting keys @see DZNPhotoPickerControllerConstants.h. + */ +- (void)photoPickerController:(DZNPhotoPickerController *)picker didSelectPhotoWithInfo:(NSDictionary *)userInfo; + +/** + Tells the delegate that the user picked a new photo and finalized its processing internally. @param picker The controller object managing the photo search picker interface. @param userInfo A dictionary containing the original image and the edited image. The dictionary also contains any relevant editing information (crop size, crop mode). For exiting keys @see DZNPhotoPickerControllerConstants.h. diff --git a/Source/Classes/Core/DZNPhotoPickerController.m b/Source/Classes/Core/DZNPhotoPickerController.m index 8891930b..6c0d46b6 100644 --- a/Source/Classes/Core/DZNPhotoPickerController.m +++ b/Source/Classes/Core/DZNPhotoPickerController.m @@ -14,6 +14,7 @@ #import "DZNPhotoMetadata.h" #import +#import static DZNPhotoPickerControllerFinalizationBlock _finalizationBlock; static DZNPhotoPickerControllerFailureBlock _failureBlock; @@ -55,6 +56,7 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectPhoto:) name:DZNPhotoPickerDidSelectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPickingPhoto:) name:DZNPhotoPickerDidFinishPickingNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFailPickingPhoto:) name:DZNPhotoPickerDidFailPickingNotification object:nil]; @@ -134,6 +136,18 @@ - (void)showPhotoDisplayController } /* Called by a notification whenever the user picks a photo. */ +- (void)didSelectPhoto:(NSNotification *)notification +{ + if (self.selectionBlock) { + self.selectionBlock(self, notification.userInfo); + + } + else if (self.delegate && [self.delegate respondsToSelector:@selector(photoPickerController:didSelectPhotoWithInfo:)]){ + [self.delegate photoPickerController:self didSelectPhotoWithInfo:notification.userInfo]; + } +} + +/* Called by a notification whenever the user picks a photo and internal process was completed. */ - (void)didFinishPickingPhoto:(NSNotification *)notification { if (self.finalizationBlock) { @@ -197,6 +211,7 @@ - (void)viewDidUnload - (void)dealloc { _initialSearchTerm = nil; + _selectionBlock = nil; _finalizationBlock = nil; _cancellationBlock = nil; } diff --git a/Source/Classes/Core/DZNPhotoPickerControllerConstants.h b/Source/Classes/Core/DZNPhotoPickerControllerConstants.h index acbb7486..9b6d627a 100644 --- a/Source/Classes/Core/DZNPhotoPickerControllerConstants.h +++ b/Source/Classes/Core/DZNPhotoPickerControllerConstants.h @@ -12,7 +12,7 @@ extern NSString *const DZNPhotoPickerControllerCropMode; // An NSSt extern NSString *const DZNPhotoPickerControllerCropZoomScale; // An NSString (from 1.0 to maximum zoom scale, 2.0f) extern NSString *const DZNPhotoPickerControllerPhotoMetadata; // An NSDictionary containing metadata from a captured photo -extern NSString *const DZNPhotoPickerDidSelectPickingNotification; // The notification key used when picking a photo selected and download started. +extern NSString *const DZNPhotoPickerDidSelectNotification; // The notification key used when selecting a photo, and finalization will start. extern NSString *const DZNPhotoPickerDidFinishPickingNotification; // The notification key used when picking a photo finished. extern NSString *const DZNPhotoPickerDidFailPickingNotification; // The notification key used when picking a photo failed. diff --git a/Source/Classes/Core/DZNPhotoPickerControllerConstants.m b/Source/Classes/Core/DZNPhotoPickerControllerConstants.m index 944b08af..58141315 100644 --- a/Source/Classes/Core/DZNPhotoPickerControllerConstants.m +++ b/Source/Classes/Core/DZNPhotoPickerControllerConstants.m @@ -14,6 +14,7 @@ NSString *const DZNPhotoPickerControllerCropZoomScale = @"com.dzn.photoPicker.cropZoomScale"; NSString *const DZNPhotoPickerControllerPhotoMetadata = @"com.dzn.photoPicker.photoMetadata"; +NSString *const DZNPhotoPickerDidSelectNotification = @"com.dzn.photoPicker.didSelectNotification"; NSString *const DZNPhotoPickerDidFinishPickingNotification = @"com.dzn.photoPicker.didFinishPickingNotification"; NSString *const DZNPhotoPickerDidFailPickingNotification = @"com.dzn.photoPicker.didFinishPickingWithErrorNotification"; diff --git a/Source/Classes/Services/DZNPhotoMetadata.m b/Source/Classes/Services/DZNPhotoMetadata.m index 744c2406..d7d4e2ac 100644 --- a/Source/Classes/Services/DZNPhotoMetadata.m +++ b/Source/Classes/Services/DZNPhotoMetadata.m @@ -156,7 +156,7 @@ - (void)postMetadataUpdate:(NSDictionary *)userInfo notification:(NSString *)nam NSDictionary *payload = [self payload]; if (payload.allKeys.count > 0) { - [_userInfo setObject:payload forKey:DZNPhotoPickerControllerPhotoMetadata]; + _userInfo[DZNPhotoPickerControllerPhotoMetadata] = payload; } [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:_userInfo];