diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index 32e667af..8ac2135d 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -24,4 +24,18 @@ Pod::Spec.new do |spec| spec.ios.frameworks = 'Photos' spec.requires_arc = true spec.dependency 'PureLayout', '~> 3.0.0' + + # only the core libary is used by default + spec.default_subspec = 'Core' + + # subspec for the main functionality. + spec.subspec 'Core' do |core| + + end + + # subspec for GIF plugin. + spec.subspec 'GIF' do |gif| + gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DCTASSETS_GIF_ENABLED' } + gif.dependency 'YYImage' + end end diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 3e5acadb..08addb97 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -86,6 +86,20 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setupScrollViewButtons]; + +#ifdef CTASSETS_GIF_ENABLED + // Get resource objects that describe the data files that an asset represents. + NSArray *assetResources = [PHAssetResource assetResourcesForAsset: self.asset]; + + // To determine GIF type only the first asset resource is required. + PHAssetResource *firstFoundResource = assetResources[0]; + + if([firstFoundResource.uniformTypeIdentifier isEqualToString:(NSString *)kUTTypeGIF]) + { + [self requestAssetAnimatedImage]; + return; + } +#endif [self requestAssetImage]; } @@ -227,6 +241,44 @@ - (PHImageRequestOptions *)imageRequestOptions return options; } +#ifdef CTASSETS_GIF_ENABLED + +#pragma mark - Request animated image + +- (void)requestAssetAnimatedImage { + [self.scrollView setProgress:0]; + + PHImageRequestOptions *options = [self imageRequestOptions]; + + self.imageRequestID = + [self.imageManager requestImageDataForAsset:self.asset + options:options + resultHandler:^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) { + + NSError *error = [info objectForKey:PHImageErrorKey]; + + if(error) + { + dispatch_async(dispatch_get_main_queue(), ^{ + + [self showRequestImageError:error title:nil]; + }); + } + else + { + YYImage *animatedImage = [YYImage imageWithData:imageData]; + + self.image = animatedImage; + + dispatch_async(dispatch_get_main_queue(), ^{ + + [self.scrollView bind:self.asset image:animatedImage requestInfo:info]; + }); + } + }]; +} + +#endif #pragma mark - Request player item diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index bd7f81ac..33e64066 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -29,6 +29,12 @@ #import "CTAssetPlayButton.h" #import "CTAssetSelectionButton.h" +#ifdef CTASSETS_GIF_ENABLED + +#import +#import "YYImage/YYImage.h" + +#endif NS_ASSUME_NONNULL_BEGIN diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index ae9dd0de..7f802c06 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -52,7 +52,12 @@ @interface CTAssetScrollView () @property (nonatomic, assign) CGFloat perspectiveZoomScale; -@property (nonatomic, strong) UIImageView *imageView; +#ifdef CTASSETS_GIF_ENABLED + // YYAnimatedImageView is a subclass of UIImageView with support for playing GIFs + @property (nonatomic, strong) YYAnimatedImageView *imageView; +#else + @property (nonatomic, strong) UIImageView *imageView; +#endif @property (nonatomic, strong) UIProgressView *progressView; @property (nonatomic, strong) UIActivityIndicatorView *activityView; @@ -104,7 +109,12 @@ - (void)dealloc - (void)setupViews { +#ifdef CTASSETS_GIF_ENABLED + YYAnimatedImageView *imageView = [YYAnimatedImageView new]; +#else UIImageView *imageView = [UIImageView new]; +#endif + imageView.isAccessibilityElement = YES; imageView.accessibilityTraits = UIAccessibilityTraitImage; self.imageView = imageView; diff --git a/Podfile.lock b/Podfile.lock index 3b0fa5f8..5c22eb9c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,8 @@ PODS: - - CTAssetsPickerController (3.3.1): + - CTAssetsPickerController (3.3.2-alpha): + - CTAssetsPickerController/Core (= 3.3.2-alpha) + - PureLayout (~> 3.0.0) + - CTAssetsPickerController/Core (3.3.2-alpha): - PureLayout (~> 3.0.0) - PureLayout (3.0.1) @@ -8,10 +11,10 @@ DEPENDENCIES: EXTERNAL SOURCES: CTAssetsPickerController: - :path: . + :path: "." SPEC CHECKSUMS: - CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed + CTAssetsPickerController: d0e938e161a59cddf159621371c1be220a7d4b05 PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb COCOAPODS: 0.39.0