diff --git a/.DS_Store b/.DS_Store index 2d6a6b3..6d82e09 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/ConvenientImagePicker/.DS_Store b/ConvenientImagePicker/.DS_Store index 3bb46a6..13ba8a9 100644 Binary files a/ConvenientImagePicker/.DS_Store and b/ConvenientImagePicker/.DS_Store differ diff --git a/ConvenientImagePicker/Classes/PickerViewController.swift b/ConvenientImagePicker/Classes/PickerViewController.swift index f4de493..33c3087 100644 --- a/ConvenientImagePicker/Classes/PickerViewController.swift +++ b/ConvenientImagePicker/Classes/PickerViewController.swift @@ -132,7 +132,7 @@ public class PickerViewController: UIViewController { var assetsFetchResults: PHFetchResult! var imageManager: PHCachingImageManager! - var selectedImages = [Int : UIImage]() + var selectedImagesIndex = Set() public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { @@ -238,7 +238,12 @@ public class PickerViewController: UIViewController { self.mainView.frame = CGRect(x: 0, y: screenHeight, width: screenWidth, height: screenHeight + 50.0) self.backView.alpha = 0 }) { (true) in - self.delegate?.imagePickerDidCancel(self.selectedImages) + var selectedImages = [Int : UIImage]() + for oneIndex in self.selectedImagesIndex + { + selectedImages[oneIndex] = self.GetImageFromIndex(item: oneIndex) + } + self.delegate?.imagePickerDidCancel(selectedImages) self.dismiss(animated: true, completion: nil) } } diff --git a/ConvenientImagePicker/Classes/PickerViewDataSource.swift b/ConvenientImagePicker/Classes/PickerViewDataSource.swift index 9445bef..89275cf 100644 --- a/ConvenientImagePicker/Classes/PickerViewDataSource.swift +++ b/ConvenientImagePicker/Classes/PickerViewDataSource.swift @@ -136,15 +136,15 @@ extension PickerViewController: UICollectionViewDelegateFlowLayout, UICollection { guard let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "PickerCollectionCell", for: indexPath) as? PickerCollectionCell else { return UICollectionViewCell() } cell.image.layer.borderColor = UIColor.systemBlue.cgColor - cell.image.layer.borderWidth = self.selectedImages[indexPath.item] == nil ? 0.0 : 3.0 - cell.selectedImageView.alpha = self.selectedImages[indexPath.item] == nil ? 0 : 1 - cell.upper.alpha = self.selectedImages[indexPath.item] == nil ? 0 : 0.3 + cell.image.layer.borderWidth = self.selectedImagesIndex.contains(indexPath.item) ? 3.0 : 0.0 + cell.selectedImageView.alpha = self.selectedImagesIndex.contains(indexPath.item) ? 1 : 0 + cell.upper.alpha = self.selectedImagesIndex.contains(indexPath.item) ? 0.3 : 0 if self.images == nil { let asset = self.assetsFetchResults[indexPath.item] //获取缩略图 - self.imageManager.requestImage(for: asset, targetSize: CGSize(width: 500, height: 500), + self.imageManager.requestImage(for: asset, targetSize: CGSize(width: 200, height: 200), contentMode: PHImageContentMode.aspectFill, options: nil) { (image, nfo) in cell.image.image = image @@ -179,8 +179,9 @@ extension PickerViewController: UICollectionViewDelegateFlowLayout, UICollection func PickerCollectionCellOp(indexPath: IndexPath) { let image = self.GetImageFromIndex(item: indexPath.item) - self.selectedImages[indexPath.item] = image - self._selectedImageCount = self.selectedImages.count + //self.selectedImages[indexPath.item] = image + self.selectedImagesIndex.insert(indexPath.item) + self._selectedImageCount = self.selectedImagesIndex.count self.delegate?.imageDidSelect(self, index: indexPath.item, image: image) self.CountViewUpdate() if !self.allowMultipleSelection @@ -192,8 +193,9 @@ extension PickerViewController: UICollectionViewDelegateFlowLayout, UICollection func PickerCollectionCellDeOp(indexPath: IndexPath) { let image = self.GetImageFromIndex(item: indexPath.item) - self.selectedImages[indexPath.item] = nil - self._selectedImageCount = self.selectedImages.count + //self.selectedImages[indexPath.item] = nil + self.selectedImagesIndex.remove(indexPath.item) + self._selectedImageCount = self.selectedImagesIndex.count self.delegate?.imageDidDeselect(self, index: indexPath.item, image: image) self.CountViewUpdate() } diff --git a/Documentation/.DS_Store b/Documentation/.DS_Store index b229809..13be6c0 100644 Binary files a/Documentation/.DS_Store and b/Documentation/.DS_Store differ diff --git a/Example/ConvenientImagePicker.xcworkspace/xcuserdata/land.xcuserdatad/UserInterfaceState.xcuserstate b/Example/ConvenientImagePicker.xcworkspace/xcuserdata/land.xcuserdatad/UserInterfaceState.xcuserstate index 6c88bbe..ecf18a3 100644 Binary files a/Example/ConvenientImagePicker.xcworkspace/xcuserdata/land.xcuserdatad/UserInterfaceState.xcuserstate and b/Example/ConvenientImagePicker.xcworkspace/xcuserdata/land.xcuserdatad/UserInterfaceState.xcuserstate differ