Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the feature for playing GIFs in full-screen preview #211

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
45af881
Add feature for playing GIFs in full-screen preview
storix Feb 2, 2016
d8d1112
Merge branch 'master' into play-gifs-feature
stanmots Apr 8, 2016
23508de
Fix merging conflicts
stanmots Apr 8, 2016
37a5888
Drop iOS 8 support
stanmots Apr 9, 2016
d67f813
Configure GIF plugin as an optional dependency
stanmots Apr 9, 2016
a12c808
Delete unnecessary properties
stanmots Apr 9, 2016
68f9bf2
Delete unnecessary demo example
stanmots Apr 9, 2016
8dcf9af
Implement conditional compiling for GIF plugin
stanmots Apr 9, 2016
8c88cb6
Improve Swift support
stanmots Apr 9, 2016
75e0f4d
Conditionally compile CTAssetAnimatedImage
stanmots Apr 9, 2016
dc961a1
Prevent duplicated CTAssetAnimatedImage compiling
stanmots Apr 10, 2016
10ee11e
Remove redundant project file setting
stanmots Apr 10, 2016
559aaba
Fix indentation in podspec
stanmots Apr 10, 2016
c2835ad
Revert line paddings to the original state
stanmots Apr 10, 2016
2bcc567
Change dependency to YYImage in podspec
stanmots Apr 21, 2016
7bfb101
Change type in accordance with the new YYImage lib
stanmots Apr 21, 2016
3078f47
Remove unnecessary conditional check
stanmots Apr 21, 2016
b325c2a
Remove deprecated CTAssetAnimatedImage class
stanmots Apr 21, 2016
0795f7a
Rename GIF dependency compilation flag to CTASSETS_GIF_ENABLED
stanmots Apr 21, 2016
534b332
Rename preprocessor macro in accordance with new compilation flag
stanmots Apr 21, 2016
d44b5fb
Change YYImage header to modular type
stanmots Apr 21, 2016
68f6f6b
Improve consistency with the original code
stanmots Apr 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CTAssetsPickerController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions CTAssetsPickerController/CTAssetItemViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions CTAssetsPickerController/CTAssetScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#import "CTAssetPlayButton.h"
#import "CTAssetSelectionButton.h"

#ifdef CTASSETS_GIF_ENABLED

#import <MobileCoreServices/MobileCoreServices.h>
#import "YYImage/YYImage.h"

#endif

NS_ASSUME_NONNULL_BEGIN

Expand Down
12 changes: 11 additions & 1 deletion CTAssetsPickerController/CTAssetScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -8,10 +11,10 @@ DEPENDENCIES:

EXTERNAL SOURCES:
CTAssetsPickerController:
:path: .
:path: "."

SPEC CHECKSUMS:
CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed
CTAssetsPickerController: d0e938e161a59cddf159621371c1be220a7d4b05
PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb

COCOAPODS: 0.39.0