From d9f4e8f627c70df6d72addff4b63aa370d112f2b Mon Sep 17 00:00:00 2001 From: Mohd Asif Date: Tue, 21 Mar 2017 10:20:42 +0530 Subject: [PATCH 1/2] Fix: collectionview was not scrolling to the end --- QBImagePicker/QBAssetsViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QBImagePicker/QBAssetsViewController.m b/QBImagePicker/QBAssetsViewController.m index 98177684..0c47daa2 100644 --- a/QBImagePicker/QBAssetsViewController.m +++ b/QBImagePicker/QBAssetsViewController.m @@ -107,10 +107,10 @@ - (void)viewWillAppear:(BOOL)animated if (self.fetchResult.count > 0 && self.isMovingToParentViewController && !self.disableScrollToBottom) { // when presenting as a .FormSheet on iPad, the frame is not correct until just after viewWillAppear: // dispatching to the main thread waits one run loop until the frame is update and the layout is complete - dispatch_async(dispatch_get_main_queue(), ^{ + [self.collectionView performBatchUpdates:^{} completion: ^(BOOL finished) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:(self.fetchResult.count - 1) inSection:0]; [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:NO]; - }); + }]; } } From 82d9d3e5d25cbd7c65d5bcf2f1e4cce8d676af9c Mon Sep 17 00:00:00 2001 From: Sumeet Gupta Date: Thu, 27 Apr 2017 16:34:30 +0530 Subject: [PATCH 2/2] Add support for loading iCloud photos --- QBImagePicker/QBAssetsViewController.m | 50 ++++++++++++++++++++++++- QBImagePicker/QBImagePicker.storyboard | 20 +++++++++- QBImagePicker/QBImagePickerController.h | 2 + 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/QBImagePicker/QBAssetsViewController.m b/QBImagePicker/QBAssetsViewController.m index 0c47daa2..4062fcfa 100644 --- a/QBImagePicker/QBAssetsViewController.m +++ b/QBImagePicker/QBAssetsViewController.m @@ -57,6 +57,8 @@ - (NSArray *)qb_indexPathsForElementsInRect:(CGRect)rect @interface QBAssetsViewController () @property (nonatomic, strong) IBOutlet UIBarButtonItem *doneButton; +@property (weak, nonatomic) IBOutlet UIView *activityContainerView; +@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator; @property (nonatomic, strong) PHFetchResult *fetchResult; @@ -73,14 +75,38 @@ @implementation QBAssetsViewController - (void)viewDidLoad { [super viewDidLoad]; - + [self setUpToolbarItems]; [self resetCachedAssets]; + if (self.imagePickerController.downloadiCloudPhotos) { + [self setupActivityContainerView]; + } // Register observer [[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self]; } +- (void)setupActivityContainerView { + [self.view addSubview:self.activityContainerView]; + [self addConstriantsToActivityView:self.activityContainerView subView:self.view]; +} + +- (void)addConstriantsToActivityView:(UIView *)subView subView: (UIView *)superView { + subView.translatesAutoresizingMaskIntoConstraints = false; + + NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]; + + NSLayoutConstraint *trailingConstraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0]; + + NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; + + NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]; + + NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:[[UIScreen mainScreen] bounds].size.height]; + + [superView addConstraints:@[leadingConstraint, trailingConstraint, topConstraint, bottomConstraint, heightConstraint]]; +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; @@ -603,7 +629,21 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa } } else { if ([imagePickerController.delegate respondsToSelector:@selector(qb_imagePickerController:didFinishPickingAssets:)]) { - [imagePickerController.delegate qb_imagePickerController:imagePickerController didFinishPickingAssets:@[asset]]; + + if ([asset isKindOfClass:[PHAsset class]] && self.imagePickerController.downloadiCloudPhotos) { + [self showActivityIndicator:true]; + PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; + [options setNetworkAccessAllowed:true]; + [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + UIImage *image = [UIImage imageWithData:imageData scale:1.0]; + if (image) { + [self showActivityIndicator:false]; + [imagePickerController.delegate qb_imagePickerController:imagePickerController didFinishPickingAssets:@[asset]]; + } + }]; + } else { + [imagePickerController.delegate qb_imagePickerController:imagePickerController didFinishPickingAssets:@[asset]]; + } } } @@ -612,6 +652,12 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa } } +- (void)showActivityIndicator:(BOOL) show { + [self.view bringSubviewToFront:self.activityContainerView]; + self.activityContainerView.hidden = !show; + (show ? [self.activityIndicator startAnimating] : [self.activityIndicator stopAnimating]); +} + - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { if (!self.imagePickerController.allowsMultipleSelection) { diff --git a/QBImagePicker/QBImagePicker.storyboard b/QBImagePicker/QBImagePicker.storyboard index cba77d90..44c898d0 100644 --- a/QBImagePicker/QBImagePicker.storyboard +++ b/QBImagePicker/QBImagePicker.storyboard @@ -1,5 +1,8 @@ - - + + + + + @@ -262,10 +265,23 @@ + + + diff --git a/QBImagePicker/QBImagePickerController.h b/QBImagePicker/QBImagePickerController.h index e7547e59..ddca4918 100644 --- a/QBImagePicker/QBImagePickerController.h +++ b/QBImagePicker/QBImagePickerController.h @@ -48,4 +48,6 @@ typedef NS_ENUM(NSUInteger, QBImagePickerMediaType) { @property (nonatomic, assign) NSUInteger numberOfColumnsInPortrait; @property (nonatomic, assign) NSUInteger numberOfColumnsInLandscape; +@property (nonatomic, assign) BOOL downloadiCloudPhotos; + @end