diff --git a/QBImagePicker/Info.plist b/QBImagePicker/Info.plist index fcc63473..3d73e614 100644 --- a/QBImagePicker/Info.plist +++ b/QBImagePicker/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.2 + 3.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/QBImagePicker/QBAssetsViewController.m b/QBImagePicker/QBAssetsViewController.m index b26ecf75..6923071b 100644 --- a/QBImagePicker/QBAssetsViewController.m +++ b/QBImagePicker/QBAssetsViewController.m @@ -59,11 +59,13 @@ @interface QBAssetsViewController () = self.imagePickerController.minimumNumberOfSelection); +} + #pragma mark - Actions @@ -230,6 +245,13 @@ - (void)updateFetchRequest } self.fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetCollection options:options]; + + if ([self isAutoDeselectEnabled] && self.imagePickerController.selectedAssets.count > 0) { + // Get index of previous selected asset + PHAsset *asset = [self.imagePickerController.selectedAssets firstObject]; + NSInteger assetIndex = [self.fetchResult indexOfObject:asset]; + self.lastSelectedItemIndexPath = [NSIndexPath indexPathForItem:assetIndex inSection:0]; + } } else { self.fetchResult = nil; } @@ -254,7 +276,7 @@ - (BOOL)isMaximumSelectionLimitReached return NO; } -- (void)updateControlState +- (void)updateDoneButtonState { self.doneButton.enabled = [self isMinimumSelectionLimitFulfilled]; } @@ -525,20 +547,37 @@ - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtInde return [self.imagePickerController.delegate qb_imagePickerController:self.imagePickerController shouldSelectAsset:asset]; } + if ([self isAutoDeselectEnabled]) { + return YES; + } + return ![self isMaximumSelectionLimitReached]; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { QBImagePickerController *imagePickerController = self.imagePickerController; + NSMutableOrderedSet *selectedAssets = imagePickerController.selectedAssets; + PHAsset *asset = self.fetchResult[indexPath.item]; if (imagePickerController.allowsMultipleSelection) { + if ([self isAutoDeselectEnabled] && selectedAssets.count > 0) { + // Remove previous selected asset from set + [selectedAssets removeObjectAtIndex:0]; + + // Deselect previous selected asset + if (self.lastSelectedItemIndexPath) { + [collectionView deselectItemAtIndexPath:self.lastSelectedItemIndexPath animated:NO]; + } + } + // Add asset to set - NSMutableOrderedSet *selectedAssets = imagePickerController.selectedAssets; [selectedAssets addObject:asset]; - [self updateControlState]; + self.lastSelectedItemIndexPath = indexPath; + + [self updateDoneButtonState]; if (imagePickerController.showsNumberOfSelectedAssets) { [self updateSelectionInfo]; @@ -568,11 +607,14 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex QBImagePickerController *imagePickerController = self.imagePickerController; NSMutableOrderedSet *selectedAssets = imagePickerController.selectedAssets; - // Remove asset from set PHAsset *asset = self.fetchResult[indexPath.item]; + + // Remove asset from set [selectedAssets removeObject:asset]; - [self updateControlState]; + self.lastSelectedItemIndexPath = nil; + + [self updateDoneButtonState]; if (imagePickerController.showsNumberOfSelectedAssets) { [self updateSelectionInfo]; diff --git a/QBImagePickerController.podspec b/QBImagePickerController.podspec index c7444c4e..c2012504 100644 --- a/QBImagePickerController.podspec +++ b/QBImagePickerController.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "QBImagePickerController" - s.version = "3.0.2" + s.version = "3.1.0" s.summary = "A clone of UIImagePickerController with multiple selection support." s.homepage = "https://github.com/questbeat/QBImagePicker" s.license = "MIT" diff --git a/README.md b/README.md index ff653f0c..d433de57 100755 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ A clone of UIImagePickerController with multiple selection support. ## Requirements -- iOS 8.0 or later +- Version `>= 3.0.0` : iOS 8 or later (Using PhotoKit) +- Version `< 3.0.0` : iOS 6 or later (Using AssetsLibrary) +