From 45af8817810239aba4028f862af7a8323541c5d0 Mon Sep 17 00:00:00 2001 From: Storix Date: Tue, 2 Feb 2016 20:56:29 +0200 Subject: [PATCH 01/21] Add feature for playing GIFs in full-screen preview --- CTAssetsPickerController.podspec | 1 + .../CTAssetAnimatedImage.h | 55 +++++++ .../CTAssetAnimatedImage.m | 41 +++++ .../CTAssetCollectionViewController.h | 2 + .../CTAssetCollectionViewController.m | 4 + .../CTAssetItemViewController.h | 1 + .../CTAssetItemViewController.m | 152 +++++++++++++++++- CTAssetsPickerController/CTAssetScrollView.h | 2 +- CTAssetsPickerController/CTAssetScrollView.m | 23 ++- .../CTAssetsGridViewController.h | 2 + .../CTAssetsGridViewController.m | 2 + .../CTAssetsPageViewController.h | 5 + .../CTAssetsPageViewController.m | 4 + .../CTAssetsPickerController.h | 7 + .../CTAssetsPickerController.m | 3 + CTAssetsPickerDemo.xcodeproj/project.pbxproj | 6 + CTAssetsPickerDemo/CTMasterViewController.m | 9 +- .../CTPlayAnimatedImagesViewController.h | 31 ++++ .../CTPlayAnimatedImagesViewController.m | 60 +++++++ 19 files changed, 395 insertions(+), 15 deletions(-) create mode 100644 CTAssetsPickerController/CTAssetAnimatedImage.h create mode 100644 CTAssetsPickerController/CTAssetAnimatedImage.m create mode 100644 CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h create mode 100644 CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index 76a7f70f..99769688 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -24,4 +24,5 @@ Pod::Spec.new do |spec| spec.ios.frameworks = 'Photos' spec.requires_arc = true spec.dependency 'PureLayout', '~> 3.0.0' + spec.dependency 'FLAnimatedImage', '~> 1.0' end diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.h b/CTAssetsPickerController/CTAssetAnimatedImage.h new file mode 100644 index 00000000..17cf41a7 --- /dev/null +++ b/CTAssetsPickerController/CTAssetAnimatedImage.h @@ -0,0 +1,55 @@ +/* + + MIT License (MIT) + + Copyright (c) 2016 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import +#import + + + + + +/** + * A wrapper class around FLAnimatedImage for using it as a drop-in replacement for UIImage + */ +@interface CTAssetAnimatedImage : UIImage + +/** + * Original animated image this class was initialized with. + */ +@property (nonatomic, readonly) FLAnimatedImage *animatedImage; + + +/** + * Initializes a wrapper with an animated image. + * + * @param animatedImage An animated image (GIF) represented by the FLAnimatedImage instance. + * + * @return An instance of `CTAssetAnimatedImage` associated with an animated image. + */ +- (instancetype)initWithAnimatedImage:(FLAnimatedImage *)animatedImage; + + +@end diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.m b/CTAssetsPickerController/CTAssetAnimatedImage.m new file mode 100644 index 00000000..c329e1b4 --- /dev/null +++ b/CTAssetsPickerController/CTAssetAnimatedImage.m @@ -0,0 +1,41 @@ +/* + + MIT License (MIT) + + Copyright (c) 2016 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import "CTAssetAnimatedImage.h" + +@implementation CTAssetAnimatedImage + +- (instancetype)initWithAnimatedImage:(FLAnimatedImage *)animatedImage +{ + // this instance can be used itself as a poster image + if (self = [super initWithCGImage:animatedImage.posterImage.CGImage]) { + _animatedImage = animatedImage; + } + + return self; +} + +@end diff --git a/CTAssetsPickerController/CTAssetCollectionViewController.h b/CTAssetsPickerController/CTAssetCollectionViewController.h index 91c1d2c7..c16e90fe 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewController.h +++ b/CTAssetsPickerController/CTAssetCollectionViewController.h @@ -28,6 +28,8 @@ @interface CTAssetCollectionViewController : UITableViewController +@property (nonatomic, assign) BOOL allowsAnimatedImages; + - (void)reloadUserInterface; @end \ No newline at end of file diff --git a/CTAssetsPickerController/CTAssetCollectionViewController.m b/CTAssetsPickerController/CTAssetCollectionViewController.m index 953473f5..084dcd24 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewController.m +++ b/CTAssetsPickerController/CTAssetCollectionViewController.m @@ -67,6 +67,8 @@ - (instancetype)init if (self = [super initWithStyle:UITableViewStylePlain]) { _imageManager = [PHCachingImageManager new]; + _allowsAnimatedImages = NO; + [self addNotificationObserver]; } @@ -486,6 +488,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath PHAssetCollection *collection = self.assetCollections[indexPath.row]; CTAssetsGridViewController *vc = [CTAssetsGridViewController new]; + vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.title = self.picker.selectedAssetsString ? : collection.localizedTitle; vc.assetCollection = collection; vc.delegate = self; @@ -505,6 +508,7 @@ - (void)showDefaultAssetCollection if (self.defaultAssetCollection && !self.didShowDefaultAssetCollection) { CTAssetsGridViewController *vc = [CTAssetsGridViewController new]; + vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.title = self.picker.selectedAssetsString ? : self.defaultAssetCollection.localizedTitle; vc.assetCollection = self.defaultAssetCollection; vc.delegate = self; diff --git a/CTAssetsPickerController/CTAssetItemViewController.h b/CTAssetsPickerController/CTAssetItemViewController.h index 7efc8646..c959fb95 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.h +++ b/CTAssetsPickerController/CTAssetItemViewController.h @@ -32,6 +32,7 @@ @interface CTAssetItemViewController : UIViewController @property (nonatomic, assign) BOOL allowsSelection; +@property (nonatomic, assign) BOOL allowsAnimatedImages; @property (nonatomic, strong, readonly) PHAsset *asset; @property (nonatomic, strong, readonly) UIImage *image; diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 7c0b62c7..066f93ef 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -24,15 +24,14 @@ of this software and associated documentation files (the "Software"), to deal */ - +#import #import #import "CTAssetsPickerController.h" #import "CTAssetItemViewController.h" #import "CTAssetScrollView.h" #import "NSBundle+CTAssetsPickerController.h" #import "PHAsset+CTAssetsPickerController.h" - - +#import "CTAssetAnimatedImage.h" @interface CTAssetItemViewController () @@ -44,6 +43,7 @@ @interface CTAssetItemViewController () @property (nonatomic, strong) PHImageManager *imageManager; @property (nonatomic, assign) PHImageRequestID imageRequestID; +@property (nonatomic, assign) PHImageRequestID animatedImageRequestID; @property (nonatomic, assign) PHImageRequestID playerItemRequestID; @property (nonatomic, strong) CTAssetScrollView *scrollView; @@ -52,7 +52,17 @@ @interface CTAssetItemViewController () @end - +/** + * Compatibility mode for requesting animated images. + * + * @note In iOS 8 just to know whether a current asset is GIF we must download the full-sized image data. Such approach is very inefficient considering that the image could be in iCloud. Therefore, for iOS 8 it's better to use 'CTAssetRequestAnimatedImageLocalFilesOnly' mode which guarantees playing only local GIFs (for iCloud images only poster image will be downloaded). + */ +typedef NS_ENUM(NSUInteger, CTAssetRequestAnimatedImageMode) { + /** Request GIFs for on-device files only. Compatible with iOS 8.*/ + CTAssetRequestAnimatedImageLocalFilesOnly = 0, + /** Request GIFs for both on-device and iCloud files. Native mode in iOS 9+. */ + CTAssetRequestAnimatedImageNormalMode +}; @implementation CTAssetItemViewController @@ -69,6 +79,7 @@ - (instancetype)initWithAsset:(PHAsset *)asset _imageManager = [PHImageManager defaultManager]; self.asset = asset; self.allowsSelection = NO; + self.allowsAnimatedImages = NO; } return self; @@ -85,7 +96,44 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setupScrollViewButtons]; - [self requestAssetImage]; + + // ensure that we are not making the same request multiple times + if(self.image == nil) + { + if (self.allowsAnimatedImages) + { + // [iOS 9 SECTION BEGINS] + // Note: In iOS 9 there is a quick way to determine GIF type using PHAssetResource class + if(NSClassFromString(@"PHAssetResource")) + { + 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 requestAssetAnimatedImageWithCompatibilityMode:CTAssetRequestAnimatedImageNormalMode]; + else + [self requestAssetImage]; + } + // [iOS 9 SECTION ENDS] + else + { + // [iOS 8 SECTION BEGINS] + // Note: In iOS 8 there is no documented way to detect if the asset type is GIF without request for full-sized image data + // the only thing we can do is to filter out non-image media types + if (self.asset.mediaType == PHAssetMediaTypeImage && + (self.asset.mediaSubtypes & PHAssetMediaSubtypeNone) == 0) + + [self requestAssetAnimatedImageWithCompatibilityMode:CTAssetRequestAnimatedImageLocalFilesOnly]; + else + [self requestAssetImage]; + // [iOS 8 SECTION ENDS] + } + } + else + [self requestAssetImage]; + } } - (void)viewWillDisappear:(BOOL)animated @@ -127,6 +175,7 @@ - (void)setupViews { CTAssetScrollView *scrollView = [CTAssetScrollView newAutoLayoutView]; scrollView.allowsSelection = self.allowsSelection; + scrollView.allowsAnimatedImages = self.allowsAnimatedImages; self.scrollView = scrollView; [self.view addSubview:self.scrollView]; @@ -153,6 +202,7 @@ - (void)setupScrollViewButtons - (void)cancelRequestAsset { [self cancelRequestImage]; + [self cancelRequestAnimatedImage]; [self cancelRequestPlayerItem]; } @@ -165,6 +215,15 @@ - (void)cancelRequestImage } } +- (void)cancelRequestAnimatedImage +{ + if (self.animatedImageRequestID) + { + [self.scrollView setProgress:1]; + [self.imageManager cancelImageRequest:self.animatedImageRequestID]; + } +} + - (void)cancelRequestPlayerItem { if (self.playerItemRequestID) @@ -193,7 +252,7 @@ - (void)requestAssetImage // this image is set for transition animation self.image = image; - + dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = [info objectForKey:PHImageErrorKey]; @@ -222,7 +281,88 @@ - (PHImageRequestOptions *)imageRequestOptions [self.scrollView setProgress:progress]; }); }; + + return options; +} + + +#pragma mark - Request animated image + +- (void)requestAssetAnimatedImageWithCompatibilityMode:(CTAssetRequestAnimatedImageMode)compatibilityMode +{ + [self.scrollView setProgress:0]; + + PHImageRequestOptions *options = [self animatedImageRequestOptionsWithCompatibilityMode:compatibilityMode]; + self.animatedImageRequestID = + [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 + { + CTAssetAnimatedImage *image; + + NSNumber *isInCloud = [info objectForKey:PHImageResultIsInCloudKey]; + + BOOL isCompatibleWithCurrentOSVersion = (compatibilityMode == CTAssetRequestAnimatedImageLocalFilesOnly) ? !isInCloud.boolValue : YES; + + if([dataUTI isEqualToString:(NSString *)kUTTypeGIF] && isCompatibleWithCurrentOSVersion) + { + FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; + image = [[CTAssetAnimatedImage alloc]initWithAnimatedImage:animatedImage]; + self.image = image; + + dispatch_async(dispatch_get_main_queue(), ^{ + + [self.scrollView bind:self.asset image:image requestInfo:info]; + }); + } + else + { + // for ordinary images it's much more efficient to decompress by means of requestImageForAsset method + [self requestAssetImage]; + } + } + + }]; +} + + +- (PHImageRequestOptions *)animatedImageRequestOptionsWithCompatibilityMode:(CTAssetRequestAnimatedImageMode)compatibilityMode +{ + PHImageRequestOptions *options = [PHImageRequestOptions new]; + + switch (compatibilityMode) { + case CTAssetRequestAnimatedImageNormalMode: + options.networkAccessAllowed = YES; + break; + + case CTAssetRequestAnimatedImageLocalFilesOnly: + options.networkAccessAllowed = NO; + break; + + default: + // don't allow network access if unknown compatibility mode has been received + options.networkAccessAllowed = NO; + break; + } + + options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.scrollView setProgress:progress]; + }); + }; + return options; } diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index 740639d9..f81e6a81 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -31,7 +31,6 @@ - extern NSString * const CTAssetScrollViewDidTapNotification; extern NSString * const CTAssetScrollViewPlayerWillPlayNotification; extern NSString * const CTAssetScrollViewPlayerWillPauseNotification; @@ -40,6 +39,7 @@ extern NSString * const CTAssetScrollViewPlayerWillPauseNotification; @interface CTAssetScrollView : UIScrollView @property (nonatomic, assign) BOOL allowsSelection; +@property (nonatomic, assign) BOOL allowsAnimatedImages; @property (nonatomic, strong, readonly) UIImage *image; @property (nonatomic, strong, readonly) AVPlayer *player; diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index c079e9b1..d835814d 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -25,6 +25,8 @@ of this software and associated documentation files (the "Software"), to deal */ #import +#import "FLAnimatedImage.h" +#import "CTAssetAnimatedImage.h" #import "CTAssetScrollView.h" #import "CTAssetPlayButton.h" #import "PHAsset+CTAssetsPickerController.h" @@ -32,8 +34,6 @@ of this software and associated documentation files (the "Software"), to deal #import "UIImage+CTAssetsPickerController.h" - - NSString * const CTAssetScrollViewDidTapNotification = @"CTAssetScrollViewDidTapNotification"; NSString * const CTAssetScrollViewPlayerWillPlayNotification = @"CTAssetScrollViewPlayerWillPlayNotification"; NSString * const CTAssetScrollViewPlayerWillPauseNotification = @"CTAssetScrollViewPlayerWillPauseNotification"; @@ -52,7 +52,8 @@ @interface CTAssetScrollView () @property (nonatomic, assign) CGFloat perspectiveZoomScale; -@property (nonatomic, strong) UIImageView *imageView; +// FLAnimatedImageView is a subclass of UIImageView with support for playing GIFs +@property (nonatomic, strong) FLAnimatedImageView *imageView; @property (nonatomic, strong) UIProgressView *progressView; @property (nonatomic, strong) UIActivityIndicatorView *activityView; @@ -79,6 +80,7 @@ - (instancetype)initWithFrame:(CGRect)frame { _shouldUpdateConstraints = YES; self.allowsSelection = NO; + self.allowsAnimatedImages = NO; self.showsVerticalScrollIndicator = NO; self.showsHorizontalScrollIndicator = NO; self.bouncesZoom = YES; @@ -104,7 +106,11 @@ - (void)dealloc - (void)setupViews { - UIImageView *imageView = [UIImageView new]; + FLAnimatedImageView *imageView = [FLAnimatedImageView new]; + + // set content mode to maintain the aspect ratio + imageView.contentMode = UIViewContentModeScaleAspectFit; + imageView.isAccessibilityElement = YES; imageView.accessibilityTraits = UIAccessibilityTraitImage; self.imageView = imageView; @@ -280,12 +286,16 @@ - (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary * self.playButton.hidden = [asset ctassetsPickerIsPhoto]; BOOL isDegraded = [info[PHImageResultIsDegradedKey] boolValue]; - + if (self.image == nil || !isDegraded) { BOOL zoom = (!self.image); self.image = image; - self.imageView.image = image; + + if([image isKindOfClass:[CTAssetAnimatedImage class]]) + [(FLAnimatedImageView *)self.imageView setAnimatedImage: [(CTAssetAnimatedImage *)image animatedImage]]; + else + self.imageView.image = image; if (isDegraded) [self mimicProgress]; @@ -331,7 +341,6 @@ - (void)unbindPlayerItem } - #pragma mark - Upate zoom scales - (void)updateZoomScalesAndZoom:(BOOL)zoom diff --git a/CTAssetsPickerController/CTAssetsGridViewController.h b/CTAssetsPickerController/CTAssetsGridViewController.h index 19e34301..18888958 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.h +++ b/CTAssetsPickerController/CTAssetsGridViewController.h @@ -45,6 +45,8 @@ @property (nonatomic, weak) id delegate; @property (nonatomic, strong) PHAssetCollection *assetCollection; +@property (nonatomic, assign) BOOL allowsAnimatedImages; + @end diff --git a/CTAssetsPickerController/CTAssetsGridViewController.m b/CTAssetsPickerController/CTAssetsGridViewController.m index 99ab50ac..7f4d9e2f 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.m +++ b/CTAssetsPickerController/CTAssetsGridViewController.m @@ -79,6 +79,7 @@ - (instancetype)init if (self = [super initWithCollectionViewLayout:layout]) { _imageManager = [PHCachingImageManager new]; + _allowsAnimatedImages = NO; self.extendedLayoutIncludesOpaqueBars = YES; @@ -471,6 +472,7 @@ - (void)pushPageViewController:(UILongPressGestureRecognizer *)longPress CTAssetsPageViewController *vc = [[CTAssetsPageViewController alloc] initWithFetchResult:self.fetchResult]; vc.allowsSelection = YES; + vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.pageIndex = indexPath.item; [self.navigationController pushViewController:vc animated:YES]; diff --git a/CTAssetsPickerController/CTAssetsPageViewController.h b/CTAssetsPickerController/CTAssetsPageViewController.h index 1d00de16..334bb778 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.h +++ b/CTAssetsPickerController/CTAssetsPageViewController.h @@ -41,6 +41,11 @@ */ @property (nonatomic, assign) NSInteger pageIndex; +/** + * Indicates whether animated images (GIFs) can be played in full-screen preview. Animation is implemented by means of FLAnimatedImage high performance engine. + */ +@property (nonatomic, assign) BOOL allowsAnimatedImages; + /** * @name Creating a Assets Page View Controller diff --git a/CTAssetsPickerController/CTAssetsPageViewController.m b/CTAssetsPickerController/CTAssetsPageViewController.m index f22506a7..2c1c37bf 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.m +++ b/CTAssetsPickerController/CTAssetsPageViewController.m @@ -83,6 +83,7 @@ - (instancetype)initWithAssets:(NSArray *)assets self.dataSource = self; self.delegate = self; self.allowsSelection = NO; + self.allowsAnimatedImages = NO; self.automaticallyAdjustsScrollViewInsets = NO; } @@ -205,6 +206,7 @@ - (void)setPageIndex:(NSInteger)pageIndex CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:asset]; page.allowsSelection = self.allowsSelection; + page.allowsAnimatedImages = self.allowsAnimatedImages; [self setViewControllers:@[page] direction:UIPageViewControllerNavigationDirectionForward @@ -234,6 +236,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl PHAsset *beforeAsset = [self.assets objectAtIndex:(index - 1)]; CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:beforeAsset]; page.allowsSelection = self.allowsSelection; + page.allowsAnimatedImages = self.allowsAnimatedImages; return page; } @@ -252,6 +255,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl PHAsset *afterAsset = [self.assets objectAtIndex:(index + 1)]; CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:afterAsset]; page.allowsSelection = self.allowsSelection; + page.allowsAnimatedImages = self.allowsAnimatedImages; return page; } diff --git a/CTAssetsPickerController/CTAssetsPickerController.h b/CTAssetsPickerController/CTAssetsPickerController.h index 11eb7864..bb4d19fc 100644 --- a/CTAssetsPickerController/CTAssetsPickerController.h +++ b/CTAssetsPickerController/CTAssetsPickerController.h @@ -134,6 +134,13 @@ */ @property (nonatomic, assign) BOOL showsSelectionIndex; +/** + * Determines whether or not the animated images should be played in full-screen preview. Default value is NO. + * + * @see [CTAssetsPageViewController allowsAnimatedImages] + */ +@property (nonatomic, assign) BOOL allowsAnimatedImages; + /** * The split view controller of the picker hierarchy. (read-only) * diff --git a/CTAssetsPickerController/CTAssetsPickerController.m b/CTAssetsPickerController/CTAssetsPickerController.m index 13ee8fca..21e5f5b4 100644 --- a/CTAssetsPickerController/CTAssetsPickerController.m +++ b/CTAssetsPickerController/CTAssetsPickerController.m @@ -77,6 +77,7 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB _showsNumberOfAssets = YES; _alwaysEnableDoneButton = NO; _showsSelectionIndex = NO; + _allowsAnimatedImages = NO; _defaultAssetCollection = PHAssetCollectionSubtypeAny; [self initAssetCollectionSubtypes]; @@ -249,6 +250,8 @@ - (void)setupEmptyViewController - (void)setupSplitViewController { CTAssetCollectionViewController *vc = [CTAssetCollectionViewController new]; + vc.allowsAnimatedImages = self.allowsAnimatedImages; + CTAssetsNavigationController *master = [[CTAssetsNavigationController alloc] initWithRootViewController:vc]; UINavigationController *detail = [self emptyNavigationController]; UISplitViewController *svc = [UISplitViewController new]; diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index d9046bf4..9851aef9 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 363F8D0A685BF86C60D06D49 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */; }; + 6EE2A96C1C61124400A5616C /* CTPlayAnimatedImagesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */; }; AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; }; AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; }; AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786E11B428A73003C8863 /* CTDefaultAlbumViewController.m */; }; @@ -33,6 +34,8 @@ /* Begin PBXFileReference section */ 408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 6EE2A96A1C61124400A5616C /* CTPlayAnimatedImagesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTPlayAnimatedImagesViewController.h; sourceTree = ""; }; + 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTPlayAnimatedImagesViewController.m; sourceTree = ""; }; A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = ""; }; A741BBA31B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA41B5F9AB500ED3D7B /* nl-NL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nl-NL"; path = "nl-NL.lproj/LaunchScreen.strings"; sourceTree = ""; }; @@ -220,6 +223,8 @@ AD18AFD61BCC9BA9008B507D /* CTSelectionOrderViewController.m */, ADA0730B1B4625AA009FB7C7 /* CTUITweaksViewController.h */, ADA0730C1B4625AA009FB7C7 /* CTUITweaksViewController.m */, + 6EE2A96A1C61124400A5616C /* CTPlayAnimatedImagesViewController.h */, + 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */, AD4B06C91B44CD5A00D99C5A /* CTSortedAssetsViewController.h */, AD4B06CA1B44CD5A00D99C5A /* CTSortedAssetsViewController.m */, ADA073051B4515AF009FB7C7 /* CTPhotosViewController.h */, @@ -536,6 +541,7 @@ ADA073041B45118F009FB7C7 /* CTMaxSelectionViewController.m in Sources */, AD4B06CB1B44CD5A00D99C5A /* CTSortedAssetsViewController.m in Sources */, ADA073101B462C98009FB7C7 /* CTLastWeekViewController.m in Sources */, + 6EE2A96C1C61124400A5616C /* CTPlayAnimatedImagesViewController.m in Sources */, AD4B06C81B428EEF00D99C5A /* CTiCloudAlbumsViewController.m in Sources */, AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */, AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */, diff --git a/CTAssetsPickerDemo/CTMasterViewController.m b/CTAssetsPickerDemo/CTMasterViewController.m index b09c11eb..69b2aed2 100644 --- a/CTAssetsPickerDemo/CTMasterViewController.m +++ b/CTAssetsPickerDemo/CTMasterViewController.m @@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal #import "CTDefaultAlbumViewController.h" #import "CTSelectionOrderViewController.h" #import "CTUITweaksViewController.h" +#import "CTPlayAnimatedImagesViewController.h" #import "CTSortedAssetsViewController.h" @@ -71,7 +72,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger { switch (section) { case 0: - return 6; + return 7; break; case 1: @@ -166,6 +167,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (row == 5) title = @"UI tweaks"; + + if (row == 6) + title = @"Play animated images"; } if (section == 1) @@ -241,6 +245,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (row == 5) vc = (UIViewController *)[CTUITweaksViewController new]; + + if (row == 6) + vc = (UIViewController *)[CTPlayAnimatedImagesViewController new]; } if (section == 1) diff --git a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h new file mode 100644 index 00000000..b02a19a8 --- /dev/null +++ b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h @@ -0,0 +1,31 @@ +/* + + MIT License (MIT) + + Copyright (c) 2016 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import "CTBasicViewController.h" + +@interface CTPlayAnimatedImagesViewController : CTBasicViewController + +@end diff --git a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m new file mode 100644 index 00000000..73b12832 --- /dev/null +++ b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m @@ -0,0 +1,60 @@ +/* + + MIT License (MIT) + + Copyright (c) 2016 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import "CTPlayAnimatedImagesViewController.h" + + +@implementation CTPlayAnimatedImagesViewController + +- (void)pickAssets:(id)sender +{ + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){ + dispatch_async(dispatch_get_main_queue(), ^{ + + // init picker + CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init]; + + // allow playing the animated images + picker.allowsAnimatedImages = YES; + + // set delegate + picker.delegate = self; + + // set default album (Camera Roll) + picker.defaultAssetCollection = PHAssetCollectionSubtypeSmartAlbumUserLibrary; + + // to present picker as a form sheet in iPad + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + picker.modalPresentationStyle = UIModalPresentationFormSheet; + + // present picker + [self presentViewController:picker animated:YES completion:nil]; + + }); + }]; +} + +@end From 23508de97f151221a06654220cb8a83d0c336eda Mon Sep 17 00:00:00 2001 From: Storix Date: Fri, 8 Apr 2016 22:29:32 +0300 Subject: [PATCH 02/21] Fix merging conflicts --- CTAssetsPickerController/CTAssetItemViewController.m | 1 + CTAssetsPickerController/CTAssetScrollView.h | 2 +- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 2 ++ Podfile.lock | 9 ++++++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index f3705d5d..43801092 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal #import "CTAssetScrollView.h" #import "NSBundle+CTAssetsPickerController.h" #import "PHAsset+CTAssetsPickerController.h" +#import "PHImageManager+CTAssetsPickerController.h" #import "CTAssetAnimatedImage.h" diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index 8e6d12d2..e06546fb 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -29,7 +29,7 @@ #import "CTAssetPlayButton.h" #import "CTAssetSelectionButton.h" - +NS_ASSUME_NONNULL_BEGIN extern NSString * const CTAssetScrollViewDidTapNotification; extern NSString * const CTAssetScrollViewPlayerWillPlayNotification; diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index 293d226f..e201d2a7 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -39,6 +39,8 @@ 408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 6EE2A96A1C61124400A5616C /* CTPlayAnimatedImagesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTPlayAnimatedImagesViewController.h; sourceTree = ""; }; 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTPlayAnimatedImagesViewController.m; sourceTree = ""; }; + 969CB85D1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LaunchScreen.strings; sourceTree = ""; }; + 969CB85E1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = ""; }; A741BBA31B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA41B5F9AB500ED3D7B /* nl-NL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nl-NL"; path = "nl-NL.lproj/LaunchScreen.strings"; sourceTree = ""; }; diff --git a/Podfile.lock b/Podfile.lock index 3b0fa5f8..22c5adef 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,8 @@ PODS: - - CTAssetsPickerController (3.3.1): + - CTAssetsPickerController (3.3.2-alpha): + - FLAnimatedImage (~> 1.0) - PureLayout (~> 3.0.0) + - FLAnimatedImage (1.0.12) - PureLayout (3.0.1) DEPENDENCIES: @@ -8,10 +10,11 @@ DEPENDENCIES: EXTERNAL SOURCES: CTAssetsPickerController: - :path: . + :path: "." SPEC CHECKSUMS: - CTAssetsPickerController: b1d1d50ab87cf6b8b13531de5f4530482e7e53ed + CTAssetsPickerController: c0cd3a15e83ca87f61dcc95d872040f933b6740e + FLAnimatedImage: 4a0b56255d9b05f18b6dd7ee06871be5d3b89e31 PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb COCOAPODS: 0.39.0 From 37a5888fb319b8eaa9785f7559acf59fddc4ea16 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 17:09:08 +0300 Subject: [PATCH 03/21] Drop iOS 8 support --- .../CTAssetItemViewController.m | 139 +++--------------- 1 file changed, 24 insertions(+), 115 deletions(-) diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 43801092..3a6ae293 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -44,7 +44,6 @@ @interface CTAssetItemViewController () @property (nonatomic, strong) PHImageManager *imageManager; @property (nonatomic, assign) PHImageRequestID imageRequestID; -@property (nonatomic, assign) PHImageRequestID animatedImageRequestID; @property (nonatomic, assign) PHImageRequestID playerItemRequestID; @property (nonatomic, strong) CTAssetScrollView *scrollView; @@ -53,19 +52,6 @@ @interface CTAssetItemViewController () @end -/** - * Compatibility mode for requesting animated images. - * - * @note In iOS 8 just to know whether a current asset is GIF we must download the full-sized image data. Such approach is very inefficient considering that the image could be in iCloud. Therefore, for iOS 8 it's better to use 'CTAssetRequestAnimatedImageLocalFilesOnly' mode which guarantees playing only local GIFs (for iCloud images only poster image will be downloaded). - */ -typedef NS_ENUM(NSUInteger, CTAssetRequestAnimatedImageMode) { - /** Request GIFs for on-device files only. Compatible with iOS 8.*/ - CTAssetRequestAnimatedImageLocalFilesOnly = 0, - /** Request GIFs for both on-device and iCloud files. Native mode in iOS 9+. */ - CTAssetRequestAnimatedImageNormalMode -}; - - @implementation CTAssetItemViewController + (CTAssetItemViewController *)assetItemViewControllerForAsset:(PHAsset *)asset @@ -97,43 +83,18 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setupScrollViewButtons]; - - // ensure that we are not making the same request multiple times - if(self.image == nil) + + // 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]) { - if (self.allowsAnimatedImages) - { - // [iOS 9 SECTION BEGINS] - // Note: In iOS 9 there is a quick way to determine GIF type using PHAssetResource class - if(NSClassFromString(@"PHAssetResource")) - { - 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 requestAssetAnimatedImageWithCompatibilityMode:CTAssetRequestAnimatedImageNormalMode]; - else - [self requestAssetImage]; - } - // [iOS 9 SECTION ENDS] - else - { - // [iOS 8 SECTION BEGINS] - // Note: In iOS 8 there is no documented way to detect if the asset type is GIF without request for full-sized image data - // the only thing we can do is to filter out non-image media types - if (self.asset.mediaType == PHAssetMediaTypeImage && - (self.asset.mediaSubtypes & PHAssetMediaSubtypeNone) == 0) - - [self requestAssetAnimatedImageWithCompatibilityMode:CTAssetRequestAnimatedImageLocalFilesOnly]; - else - [self requestAssetImage]; - // [iOS 8 SECTION ENDS] - } - } - else - [self requestAssetImage]; + [self requestAssetAnimatedImage]; + } else { + [self requestAssetImage]; } } @@ -203,7 +164,6 @@ - (void)setupScrollViewButtons - (void)cancelRequestAsset { [self cancelRequestImage]; - [self cancelRequestAnimatedImage]; [self cancelRequestPlayerItem]; } @@ -216,15 +176,6 @@ - (void)cancelRequestImage } } -- (void)cancelRequestAnimatedImage -{ - if (self.animatedImageRequestID) - { - [self.scrollView setProgress:1]; - [self.imageManager cancelImageRequest:self.animatedImageRequestID]; - } -} - - (void)cancelRequestPlayerItem { if (self.playerItemRequestID) @@ -289,13 +240,12 @@ - (PHImageRequestOptions *)imageRequestOptions #pragma mark - Request animated image -- (void)requestAssetAnimatedImageWithCompatibilityMode:(CTAssetRequestAnimatedImageMode)compatibilityMode -{ +- (void)requestAssetAnimatedImage { [self.scrollView setProgress:0]; - PHImageRequestOptions *options = [self animatedImageRequestOptionsWithCompatibilityMode:compatibilityMode]; + PHImageRequestOptions *options = [self imageRequestOptions]; - self.animatedImageRequestID = + self.imageRequestID = [self.imageManager requestImageDataForAsset:self.asset options:options resultHandler:^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) { @@ -311,63 +261,22 @@ - (void)requestAssetAnimatedImageWithCompatibilityMode:(CTAssetRequestAnimatedIm } else { - CTAssetAnimatedImage *image; + CTAssetAnimatedImage *image; + + FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; + + image = [[CTAssetAnimatedImage alloc]initWithAnimatedImage:animatedImage]; + self.image = image; + + dispatch_async(dispatch_get_main_queue(), ^{ - NSNumber *isInCloud = [info objectForKey:PHImageResultIsInCloudKey]; - - BOOL isCompatibleWithCurrentOSVersion = (compatibilityMode == CTAssetRequestAnimatedImageLocalFilesOnly) ? !isInCloud.boolValue : YES; - - if([dataUTI isEqualToString:(NSString *)kUTTypeGIF] && isCompatibleWithCurrentOSVersion) - { - FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; - image = [[CTAssetAnimatedImage alloc]initWithAnimatedImage:animatedImage]; - self.image = image; - - dispatch_async(dispatch_get_main_queue(), ^{ - - [self.scrollView bind:self.asset image:image requestInfo:info]; - }); - } - else - { - // for ordinary images it's much more efficient to decompress by means of requestImageForAsset method - [self requestAssetImage]; - } + [self.scrollView bind:self.asset image:image requestInfo:info]; + }); } - }]; } -- (PHImageRequestOptions *)animatedImageRequestOptionsWithCompatibilityMode:(CTAssetRequestAnimatedImageMode)compatibilityMode -{ - PHImageRequestOptions *options = [PHImageRequestOptions new]; - - switch (compatibilityMode) { - case CTAssetRequestAnimatedImageNormalMode: - options.networkAccessAllowed = YES; - break; - - case CTAssetRequestAnimatedImageLocalFilesOnly: - options.networkAccessAllowed = NO; - break; - - default: - // don't allow network access if unknown compatibility mode has been received - options.networkAccessAllowed = NO; - break; - } - - options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.scrollView setProgress:progress]; - }); - }; - - return options; -} - - #pragma mark - Request player item - (void)requestAssetPlayerItem:(id)sender From d67f8136984df51989b7f45243335fb808ca0837 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 17:36:53 +0300 Subject: [PATCH 04/21] Configure GIF plugin as an optional dependency --- CTAssetsPickerController.podspec | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index b2b7034c..da4cfe1e 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -24,5 +24,19 @@ Pod::Spec.new do |spec| spec.ios.frameworks = 'Photos' spec.requires_arc = true spec.dependency 'PureLayout', '~> 3.0.0' - spec.dependency 'FLAnimatedImage', '~> 1.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) -DGIF_SUPPORT_ENABLED' } + + gif.dependency 'FLAnimatedImage', '~> 1.0' + end end From a12c808adedf09bc67f89cbd2a156094cdf0db90 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 20:01:12 +0300 Subject: [PATCH 05/21] Delete unnecessary properties --- .../CTAssetCollectionViewController.h | 2 -- .../CTAssetCollectionViewController.m | 5 +---- CTAssetsPickerController/CTAssetItemViewController.h | 1 - CTAssetsPickerController/CTAssetItemViewController.m | 4 +--- CTAssetsPickerController/CTAssetScrollView.h | 1 - CTAssetsPickerController/CTAssetScrollView.m | 1 - CTAssetsPickerController/CTAssetsGridViewController.h | 1 - CTAssetsPickerController/CTAssetsGridViewController.m | 2 -- CTAssetsPickerController/CTAssetsPageViewController.h | 5 ----- CTAssetsPickerController/CTAssetsPageViewController.m | 8 ++------ CTAssetsPickerController/CTAssetsPickerController.h | 7 ------- CTAssetsPickerController/CTAssetsPickerController.m | 2 -- .../Examples/CTPlayAnimatedImagesViewController.m | 5 +---- Podfile.lock | 8 ++++---- 14 files changed, 9 insertions(+), 43 deletions(-) diff --git a/CTAssetsPickerController/CTAssetCollectionViewController.h b/CTAssetsPickerController/CTAssetCollectionViewController.h index c16e90fe..91c1d2c7 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewController.h +++ b/CTAssetsPickerController/CTAssetCollectionViewController.h @@ -28,8 +28,6 @@ @interface CTAssetCollectionViewController : UITableViewController -@property (nonatomic, assign) BOOL allowsAnimatedImages; - - (void)reloadUserInterface; @end \ No newline at end of file diff --git a/CTAssetsPickerController/CTAssetCollectionViewController.m b/CTAssetsPickerController/CTAssetCollectionViewController.m index 2552cbdc..9d34941a 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewController.m +++ b/CTAssetsPickerController/CTAssetCollectionViewController.m @@ -68,8 +68,7 @@ - (instancetype)init if (self = [super initWithStyle:UITableViewStylePlain]) { _imageManager = [PHCachingImageManager new]; - _allowsAnimatedImages = NO; - + [self addNotificationObserver]; } @@ -488,7 +487,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath PHAssetCollection *collection = self.assetCollections[indexPath.row]; CTAssetsGridViewController *vc = [CTAssetsGridViewController new]; - vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.title = self.picker.selectedAssetsString ? : collection.localizedTitle; vc.assetCollection = collection; vc.delegate = self; @@ -508,7 +506,6 @@ - (void)showDefaultAssetCollection if (self.defaultAssetCollection && !self.didShowDefaultAssetCollection) { CTAssetsGridViewController *vc = [CTAssetsGridViewController new]; - vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.title = self.picker.selectedAssetsString ? : self.defaultAssetCollection.localizedTitle; vc.assetCollection = self.defaultAssetCollection; vc.delegate = self; diff --git a/CTAssetsPickerController/CTAssetItemViewController.h b/CTAssetsPickerController/CTAssetItemViewController.h index 61bb0f20..b36d15b9 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.h +++ b/CTAssetsPickerController/CTAssetItemViewController.h @@ -32,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN @interface CTAssetItemViewController : UIViewController @property (nonatomic, assign) BOOL allowsSelection; -@property (nonatomic, assign) BOOL allowsAnimatedImages; @property (nonatomic, strong, readonly) PHAsset *asset; @property (nonatomic, strong, readonly, nullable) UIImage *image; diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 3a6ae293..01694bc7 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -66,7 +66,6 @@ - (instancetype)initWithAsset:(PHAsset *)asset _imageManager = [PHImageManager defaultManager]; self.asset = asset; self.allowsSelection = NO; - self.allowsAnimatedImages = NO; } return self; @@ -137,8 +136,7 @@ - (void)setupViews { CTAssetScrollView *scrollView = [CTAssetScrollView newAutoLayoutView]; scrollView.allowsSelection = self.allowsSelection; - scrollView.allowsAnimatedImages = self.allowsAnimatedImages; - + self.scrollView = scrollView; [self.view addSubview:self.scrollView]; [self.view layoutIfNeeded]; diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index e06546fb..219eaa49 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -39,7 +39,6 @@ extern NSString * const CTAssetScrollViewPlayerWillPauseNotification; @interface CTAssetScrollView : UIScrollView @property (nonatomic, assign) BOOL allowsSelection; -@property (nonatomic, assign) BOOL allowsAnimatedImages; @property (nonatomic, strong, readonly, nullable) UIImage *image; @property (nonatomic, strong, readonly, nullable) AVPlayer *player; diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 4f4336c2..6afb25dd 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -80,7 +80,6 @@ - (instancetype)initWithFrame:(CGRect)frame { _shouldUpdateConstraints = YES; self.allowsSelection = NO; - self.allowsAnimatedImages = NO; self.showsVerticalScrollIndicator = NO; self.showsHorizontalScrollIndicator = NO; self.bouncesZoom = YES; diff --git a/CTAssetsPickerController/CTAssetsGridViewController.h b/CTAssetsPickerController/CTAssetsGridViewController.h index f1a4de92..a2cf7842 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.h +++ b/CTAssetsPickerController/CTAssetsGridViewController.h @@ -45,7 +45,6 @@ @property (nonatomic, weak) id delegate; @property (nonatomic, strong, nonnull) PHAssetCollection *assetCollection; -@property (nonatomic, assign) BOOL allowsAnimatedImages; @end diff --git a/CTAssetsPickerController/CTAssetsGridViewController.m b/CTAssetsPickerController/CTAssetsGridViewController.m index a127fbcb..8914379f 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.m +++ b/CTAssetsPickerController/CTAssetsGridViewController.m @@ -80,7 +80,6 @@ - (instancetype)init if (self = [super initWithCollectionViewLayout:layout]) { _imageManager = [PHCachingImageManager new]; - _allowsAnimatedImages = NO; self.extendedLayoutIncludesOpaqueBars = YES; @@ -480,7 +479,6 @@ - (void)pushPageViewController:(UILongPressGestureRecognizer *)longPress CTAssetsPageViewController *vc = [[CTAssetsPageViewController alloc] initWithFetchResult:self.fetchResult]; vc.allowsSelection = YES; - vc.allowsAnimatedImages = self.allowsAnimatedImages; vc.pageIndex = indexPath.item; [self.navigationController pushViewController:vc animated:YES]; diff --git a/CTAssetsPickerController/CTAssetsPageViewController.h b/CTAssetsPickerController/CTAssetsPageViewController.h index e85048d9..30a66493 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.h +++ b/CTAssetsPickerController/CTAssetsPageViewController.h @@ -41,11 +41,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) NSInteger pageIndex; -/** - * Indicates whether animated images (GIFs) can be played in full-screen preview. Animation is implemented by means of FLAnimatedImage high performance engine. - */ -@property (nonatomic, assign) BOOL allowsAnimatedImages; - /** * @name Creating a Assets Page View Controller diff --git a/CTAssetsPickerController/CTAssetsPageViewController.m b/CTAssetsPickerController/CTAssetsPageViewController.m index ccb66df7..67044dcd 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.m +++ b/CTAssetsPickerController/CTAssetsPageViewController.m @@ -83,7 +83,6 @@ - (instancetype)initWithAssets:(NSArray *)assets self.dataSource = self; self.delegate = self; self.allowsSelection = NO; - self.allowsAnimatedImages = NO; self.automaticallyAdjustsScrollViewInsets = NO; } @@ -206,8 +205,7 @@ - (void)setPageIndex:(NSInteger)pageIndex CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:asset]; page.allowsSelection = self.allowsSelection; - page.allowsAnimatedImages = self.allowsAnimatedImages; - + [self setViewControllers:@[page] direction:UIPageViewControllerNavigationDirectionForward animated:NO @@ -236,8 +234,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl PHAsset *beforeAsset = self.assets[(index - 1)]; CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:beforeAsset]; page.allowsSelection = self.allowsSelection; - page.allowsAnimatedImages = self.allowsAnimatedImages; - + return page; } @@ -255,7 +252,6 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl PHAsset *afterAsset = self.assets[(index + 1)]; CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:afterAsset]; page.allowsSelection = self.allowsSelection; - page.allowsAnimatedImages = self.allowsAnimatedImages; return page; } diff --git a/CTAssetsPickerController/CTAssetsPickerController.h b/CTAssetsPickerController/CTAssetsPickerController.h index 980d0b8c..0afa620e 100644 --- a/CTAssetsPickerController/CTAssetsPickerController.h +++ b/CTAssetsPickerController/CTAssetsPickerController.h @@ -135,13 +135,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) BOOL showsSelectionIndex; -/** - * Determines whether or not the animated images should be played in full-screen preview. Default value is NO. - * - * @see [CTAssetsPageViewController allowsAnimatedImages] - */ -@property (nonatomic, assign) BOOL allowsAnimatedImages; - /** * The split view controller of the picker hierarchy. (read-only) * diff --git a/CTAssetsPickerController/CTAssetsPickerController.m b/CTAssetsPickerController/CTAssetsPickerController.m index 0f33e5a9..0f514595 100644 --- a/CTAssetsPickerController/CTAssetsPickerController.m +++ b/CTAssetsPickerController/CTAssetsPickerController.m @@ -77,7 +77,6 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB _showsNumberOfAssets = YES; _alwaysEnableDoneButton = NO; _showsSelectionIndex = NO; - _allowsAnimatedImages = NO; _defaultAssetCollection = PHAssetCollectionSubtypeAny; [self initAssetCollectionSubtypes]; @@ -250,7 +249,6 @@ - (void)setupEmptyViewController - (void)setupSplitViewController { CTAssetCollectionViewController *vc = [CTAssetCollectionViewController new]; - vc.allowsAnimatedImages = self.allowsAnimatedImages; CTAssetsNavigationController *master = [[CTAssetsNavigationController alloc] initWithRootViewController:vc]; UINavigationController *detail = [self emptyNavigationController]; diff --git a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m index 73b12832..d0d9ae0c 100644 --- a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m +++ b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m @@ -36,10 +36,7 @@ - (void)pickAssets:(id)sender // init picker CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init]; - - // allow playing the animated images - picker.allowsAnimatedImages = YES; - + // set delegate picker.delegate = self; diff --git a/Podfile.lock b/Podfile.lock index 22c5adef..de3ed72a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,8 +1,9 @@ PODS: - CTAssetsPickerController (3.3.2-alpha): - - FLAnimatedImage (~> 1.0) + - CTAssetsPickerController/Core (= 3.3.2-alpha) + - PureLayout (~> 3.0.0) + - CTAssetsPickerController/Core (3.3.2-alpha): - PureLayout (~> 3.0.0) - - FLAnimatedImage (1.0.12) - PureLayout (3.0.1) DEPENDENCIES: @@ -13,8 +14,7 @@ EXTERNAL SOURCES: :path: "." SPEC CHECKSUMS: - CTAssetsPickerController: c0cd3a15e83ca87f61dcc95d872040f933b6740e - FLAnimatedImage: 4a0b56255d9b05f18b6dd7ee06871be5d3b89e31 + CTAssetsPickerController: 23d8b23613c90d136a6e0e2f2b168c64af7271f5 PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb COCOAPODS: 0.39.0 From 68f9bf29030c7130c54a0428575ae2579afc4393 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 20:07:04 +0300 Subject: [PATCH 06/21] Delete unnecessary demo example --- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 10 +--- CTAssetsPickerDemo/CTMasterViewController.m | 9 +-- .../CTPlayAnimatedImagesViewController.h | 31 ---------- .../CTPlayAnimatedImagesViewController.m | 57 ------------------- 4 files changed, 4 insertions(+), 103 deletions(-) delete mode 100644 CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h delete mode 100644 CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index e201d2a7..21bfb175 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */; }; 363F8D0A685BF86C60D06D49 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */; }; - 6EE2A96C1C61124400A5616C /* CTPlayAnimatedImagesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */; }; AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; }; AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; }; AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786E11B428A73003C8863 /* CTDefaultAlbumViewController.m */; }; @@ -37,10 +36,8 @@ 0B3423A61CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PHImageManager+CTAssetsPickerController.h"; sourceTree = ""; }; 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PHImageManager+CTAssetsPickerController.m"; sourceTree = ""; }; 408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; - 6EE2A96A1C61124400A5616C /* CTPlayAnimatedImagesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTPlayAnimatedImagesViewController.h; sourceTree = ""; }; - 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTPlayAnimatedImagesViewController.m; sourceTree = ""; }; - 969CB85D1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LaunchScreen.strings; sourceTree = ""; }; - 969CB85E1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/CTAssetsPicker.strings; sourceTree = ""; }; + 969CB85D1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LaunchScreen.strings; sourceTree = ""; }; + 969CB85E1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = ""; }; A741BBA31B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA41B5F9AB500ED3D7B /* nl-NL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nl-NL"; path = "nl-NL.lproj/LaunchScreen.strings"; sourceTree = ""; }; @@ -228,8 +225,6 @@ AD18AFD61BCC9BA9008B507D /* CTSelectionOrderViewController.m */, ADA0730B1B4625AA009FB7C7 /* CTUITweaksViewController.h */, ADA0730C1B4625AA009FB7C7 /* CTUITweaksViewController.m */, - 6EE2A96A1C61124400A5616C /* CTPlayAnimatedImagesViewController.h */, - 6EE2A96B1C61124400A5616C /* CTPlayAnimatedImagesViewController.m */, AD4B06C91B44CD5A00D99C5A /* CTSortedAssetsViewController.h */, AD4B06CA1B44CD5A00D99C5A /* CTSortedAssetsViewController.m */, ADA073051B4515AF009FB7C7 /* CTPhotosViewController.h */, @@ -549,7 +544,6 @@ ADA073041B45118F009FB7C7 /* CTMaxSelectionViewController.m in Sources */, AD4B06CB1B44CD5A00D99C5A /* CTSortedAssetsViewController.m in Sources */, ADA073101B462C98009FB7C7 /* CTLastWeekViewController.m in Sources */, - 6EE2A96C1C61124400A5616C /* CTPlayAnimatedImagesViewController.m in Sources */, AD4B06C81B428EEF00D99C5A /* CTiCloudAlbumsViewController.m in Sources */, AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */, 0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */, diff --git a/CTAssetsPickerDemo/CTMasterViewController.m b/CTAssetsPickerDemo/CTMasterViewController.m index 69b2aed2..3fb1b4a9 100644 --- a/CTAssetsPickerDemo/CTMasterViewController.m +++ b/CTAssetsPickerDemo/CTMasterViewController.m @@ -33,7 +33,6 @@ of this software and associated documentation files (the "Software"), to deal #import "CTDefaultAlbumViewController.h" #import "CTSelectionOrderViewController.h" #import "CTUITweaksViewController.h" -#import "CTPlayAnimatedImagesViewController.h" #import "CTSortedAssetsViewController.h" @@ -72,7 +71,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger { switch (section) { case 0: - return 7; + return 6; break; case 1: @@ -167,9 +166,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (row == 5) title = @"UI tweaks"; - - if (row == 6) - title = @"Play animated images"; + } if (section == 1) @@ -246,8 +243,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (row == 5) vc = (UIViewController *)[CTUITweaksViewController new]; - if (row == 6) - vc = (UIViewController *)[CTPlayAnimatedImagesViewController new]; } if (section == 1) diff --git a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h deleted file mode 100644 index b02a19a8..00000000 --- a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - - MIT License (MIT) - - Copyright (c) 2016 Clement CN Tsang - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - */ - -#import "CTBasicViewController.h" - -@interface CTPlayAnimatedImagesViewController : CTBasicViewController - -@end diff --git a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m b/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m deleted file mode 100644 index d0d9ae0c..00000000 --- a/CTAssetsPickerDemo/Examples/CTPlayAnimatedImagesViewController.m +++ /dev/null @@ -1,57 +0,0 @@ -/* - - MIT License (MIT) - - Copyright (c) 2016 Clement CN Tsang - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - */ - -#import "CTPlayAnimatedImagesViewController.h" - - -@implementation CTPlayAnimatedImagesViewController - -- (void)pickAssets:(id)sender -{ - [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){ - dispatch_async(dispatch_get_main_queue(), ^{ - - // init picker - CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init]; - - // set delegate - picker.delegate = self; - - // set default album (Camera Roll) - picker.defaultAssetCollection = PHAssetCollectionSubtypeSmartAlbumUserLibrary; - - // to present picker as a form sheet in iPad - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) - picker.modalPresentationStyle = UIModalPresentationFormSheet; - - // present picker - [self presentViewController:picker animated:YES completion:nil]; - - }); - }]; -} - -@end From 8dcf9af05295a117db2c09abe923e39a36fbc115 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 21:21:32 +0300 Subject: [PATCH 07/21] Implement conditional compiling for GIF plugin --- .../CTAssetItemViewController.m | 30 ++++++++-------- CTAssetsPickerController/CTAssetScrollView.h | 9 +++++ CTAssetsPickerController/CTAssetScrollView.m | 35 +++++++++++-------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 01694bc7..24dfe763 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -24,7 +24,6 @@ of this software and associated documentation files (the "Software"), to deal */ -#import #import #import "CTAssetsPickerController.h" #import "CTAssetItemViewController.h" @@ -32,7 +31,6 @@ of this software and associated documentation files (the "Software"), to deal #import "NSBundle+CTAssetsPickerController.h" #import "PHAsset+CTAssetsPickerController.h" #import "PHImageManager+CTAssetsPickerController.h" -#import "CTAssetAnimatedImage.h" @interface CTAssetItemViewController () @@ -83,18 +81,20 @@ - (void)viewWillAppear:(BOOL)animated [super viewWillAppear:animated]; [self setupScrollViewButtons]; - // 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]; - } else { - [self requestAssetImage]; - } +#ifdef GIF_SUPPORT_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]; } - (void)viewWillDisappear:(BOOL)animated @@ -235,6 +235,7 @@ - (PHImageRequestOptions *)imageRequestOptions return options; } +#ifdef GIF_SUPPORT_ENABLED #pragma mark - Request animated image @@ -274,6 +275,7 @@ - (void)requestAssetAnimatedImage { }]; } +#endif #pragma mark - Request player item diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index 219eaa49..70bd13c1 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -29,6 +29,15 @@ #import "CTAssetPlayButton.h" #import "CTAssetSelectionButton.h" +#ifdef GIF_SUPPORT_ENABLED + +#import + +#import "FLAnimatedImage.h" +#import "CTAssetAnimatedImage.h" + +#endif + NS_ASSUME_NONNULL_BEGIN extern NSString * const CTAssetScrollViewDidTapNotification; diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 6afb25dd..0e1fb54c 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -24,9 +24,8 @@ of this software and associated documentation files (the "Software"), to deal */ + #import -#import "FLAnimatedImage.h" -#import "CTAssetAnimatedImage.h" #import "CTAssetScrollView.h" #import "CTAssetPlayButton.h" #import "PHAsset+CTAssetsPickerController.h" @@ -52,8 +51,12 @@ @interface CTAssetScrollView () @property (nonatomic, assign) CGFloat perspectiveZoomScale; -// FLAnimatedImageView is a subclass of UIImageView with support for playing GIFs -@property (nonatomic, strong) FLAnimatedImageView *imageView; +#ifdef GIF_SUPPORT_ENABLED + // FLAnimatedImageView is a subclass of UIImageView with support for playing GIFs + @property (nonatomic, strong) FLAnimatedImageView *imageView; +#else + @property (nonatomic, strong) UIImageView *imageView; +#endif @property (nonatomic, strong) UIProgressView *progressView; @property (nonatomic, strong) UIActivityIndicatorView *activityView; @@ -105,11 +108,12 @@ - (void)dealloc - (void)setupViews { +#ifdef GIF_SUPPORT_ENABLED FLAnimatedImageView *imageView = [FLAnimatedImageView new]; - - // set content mode to maintain the aspect ratio - imageView.contentMode = UIViewContentModeScaleAspectFit; - +#else + UIImageView *imageView = [UIImageView new]; +#endif + imageView.isAccessibilityElement = YES; imageView.accessibilityTraits = UIAccessibilityTraitImage; self.imageView = imageView; @@ -290,12 +294,15 @@ - (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary * { BOOL zoom = (!self.image); self.image = image; - - if([image isKindOfClass:[CTAssetAnimatedImage class]]) - [(FLAnimatedImageView *)self.imageView setAnimatedImage: [(CTAssetAnimatedImage *)image animatedImage]]; - else - self.imageView.image = image; - + +#ifdef GIF_SUPPORT_ENABLED + if([image isKindOfClass:[CTAssetAnimatedImage class]]) + [(FLAnimatedImageView *)self.imageView setAnimatedImage: [(CTAssetAnimatedImage *)image animatedImage]]; + else + self.imageView.image = image; +#else + self.imageView.image = image; +#endif if (isDegraded) [self mimicProgress]; else From 8c88cb640d5bb4567a39884831c529f836249348 Mon Sep 17 00:00:00 2001 From: Storix Date: Sat, 9 Apr 2016 23:57:59 +0300 Subject: [PATCH 08/21] Improve Swift support --- CTAssetsPickerController/CTAssetAnimatedImage.h | 8 ++------ CTAssetsPickerDemo.xcodeproj/project.pbxproj | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.h b/CTAssetsPickerController/CTAssetAnimatedImage.h index 17cf41a7..67564885 100644 --- a/CTAssetsPickerController/CTAssetAnimatedImage.h +++ b/CTAssetsPickerController/CTAssetAnimatedImage.h @@ -28,9 +28,6 @@ #import - - - /** * A wrapper class around FLAnimatedImage for using it as a drop-in replacement for UIImage */ @@ -39,7 +36,7 @@ /** * Original animated image this class was initialized with. */ -@property (nonatomic, readonly) FLAnimatedImage *animatedImage; +@property (nonnull, nonatomic, readonly) FLAnimatedImage *animatedImage; /** @@ -49,7 +46,6 @@ * * @return An instance of `CTAssetAnimatedImage` associated with an animated image. */ -- (instancetype)initWithAnimatedImage:(FLAnimatedImage *)animatedImage; - +- (nonnull instancetype)initWithAnimatedImage:(nonnull FLAnimatedImage *)animatedImage NS_DESIGNATED_INITIALIZER; @end diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index 21bfb175..a090823b 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */; }; 363F8D0A685BF86C60D06D49 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */; }; + 6E4EBEF11CB981E100A062BA /* CTAssetAnimatedImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */; }; AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; }; AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; }; AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786E11B428A73003C8863 /* CTDefaultAlbumViewController.m */; }; @@ -36,6 +37,8 @@ 0B3423A61CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PHImageManager+CTAssetsPickerController.h"; sourceTree = ""; }; 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PHImageManager+CTAssetsPickerController.m"; sourceTree = ""; }; 408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 6E4EBEEF1CB981E100A062BA /* CTAssetAnimatedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTAssetAnimatedImage.h; sourceTree = ""; }; + 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTAssetAnimatedImage.m; sourceTree = ""; }; 969CB85D1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LaunchScreen.strings; sourceTree = ""; }; 969CB85E1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = ""; }; @@ -291,6 +294,8 @@ ADD965F21AAD5780002A26A2 /* CTAssetsPickerController */ = { isa = PBXGroup; children = ( + 6E4EBEEF1CB981E100A062BA /* CTAssetAnimatedImage.h */, + 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */, ADD9660D1AAD5780002A26A2 /* CTAssetsPickerController.h */, ADD9660E1AAD5780002A26A2 /* CTAssetsPickerController.m */, AD30D7FB1AAEE01800C79E3D /* CTAssetThumbnailView.h */, @@ -552,6 +557,7 @@ AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */, ADFE238B1B46868100E44353 /* CTApperanceViewController.m in Sources */, ADE2713C1ACBA6BA0090EFB1 /* NSIndexSet+CTAssetsPickerController.m in Sources */, + 6E4EBEF11CB981E100A062BA /* CTAssetAnimatedImage.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 75e0f4db9876528a18a23bf4b38ab16005572314 Mon Sep 17 00:00:00 2001 From: Storix Date: Sun, 10 Apr 2016 00:27:45 +0300 Subject: [PATCH 09/21] Conditionally compile CTAssetAnimatedImage --- CTAssetsPickerController/CTAssetAnimatedImage.h | 4 ++++ CTAssetsPickerController/CTAssetAnimatedImage.m | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.h b/CTAssetsPickerController/CTAssetAnimatedImage.h index 67564885..6b0f7770 100644 --- a/CTAssetsPickerController/CTAssetAnimatedImage.h +++ b/CTAssetsPickerController/CTAssetAnimatedImage.h @@ -24,6 +24,8 @@ */ +#ifdef GIF_SUPPORT_ENABLED + #import #import @@ -49,3 +51,5 @@ - (nonnull instancetype)initWithAnimatedImage:(nonnull FLAnimatedImage *)animatedImage NS_DESIGNATED_INITIALIZER; @end + +#endif diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.m b/CTAssetsPickerController/CTAssetAnimatedImage.m index c329e1b4..fda19cc1 100644 --- a/CTAssetsPickerController/CTAssetAnimatedImage.m +++ b/CTAssetsPickerController/CTAssetAnimatedImage.m @@ -24,6 +24,8 @@ of this software and associated documentation files (the "Software"), to deal */ +#ifdef GIF_SUPPORT_ENABLED + #import "CTAssetAnimatedImage.h" @implementation CTAssetAnimatedImage @@ -39,3 +41,5 @@ - (instancetype)initWithAnimatedImage:(FLAnimatedImage *)animatedImage } @end + +#endif From dc961a1de387d8babac0dbbc598b280ca9241dbf Mon Sep 17 00:00:00 2001 From: Storix Date: Sun, 10 Apr 2016 11:34:47 +0300 Subject: [PATCH 10/21] Prevent duplicated CTAssetAnimatedImage compiling --- CTAssetsPickerController.podspec | 4 ++-- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index da4cfe1e..49f3f37f 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -30,12 +30,12 @@ Pod::Spec.new do |spec| # 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) -DGIF_SUPPORT_ENABLED' } + gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DGIF_SUPPORT_ENABLED' } gif.dependency 'FLAnimatedImage', '~> 1.0' end diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index a090823b..16d86743 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 0B3423A81CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */; }; 363F8D0A685BF86C60D06D49 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1B2FBB7FD634FB543BB7BB6 /* Pods.framework */; }; - 6E4EBEF11CB981E100A062BA /* CTAssetAnimatedImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */; }; AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; }; AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; }; AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786E11B428A73003C8863 /* CTDefaultAlbumViewController.m */; }; @@ -557,7 +556,6 @@ AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */, ADFE238B1B46868100E44353 /* CTApperanceViewController.m in Sources */, ADE2713C1ACBA6BA0090EFB1 /* NSIndexSet+CTAssetsPickerController.m in Sources */, - 6E4EBEF11CB981E100A062BA /* CTAssetAnimatedImage.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 10ee11e39ace7a34fd7edfd4ae130b8be9a34b55 Mon Sep 17 00:00:00 2001 From: Storix Date: Sun, 10 Apr 2016 11:54:17 +0300 Subject: [PATCH 11/21] Remove redundant project file setting --- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index 16d86743..4d0e2dd6 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -137,7 +137,7 @@ ADD966021AAD5780002A26A2 /* CTAssetItemViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetItemViewController.h; sourceTree = ""; }; ADD966031AAD5780002A26A2 /* CTAssetItemViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetItemViewController.m; sourceTree = ""; }; ADD966041AAD5780002A26A2 /* CTAssetScrollView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetScrollView.h; sourceTree = ""; }; - ADD966051AAD5780002A26A2 /* CTAssetScrollView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetScrollView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + ADD966051AAD5780002A26A2 /* CTAssetScrollView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetScrollView.m; sourceTree = ""; }; ADD966061AAD5780002A26A2 /* CTAssetCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetCollectionViewCell.h; sourceTree = ""; }; ADD966071AAD5780002A26A2 /* CTAssetCollectionViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetCollectionViewCell.m; sourceTree = ""; }; ADD966081AAD5780002A26A2 /* CTAssetCollectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetCollectionViewController.h; sourceTree = ""; }; From 559aabae0b5ff28ab353721c1d988a8d5ba32ab6 Mon Sep 17 00:00:00 2001 From: Storix Date: Sun, 10 Apr 2016 12:14:06 +0300 Subject: [PATCH 12/21] Fix indentation in podspec --- CTAssetsPickerController.podspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index 49f3f37f..dfa07bdc 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -35,8 +35,7 @@ Pod::Spec.new do |spec| # subspec for GIF plugin. spec.subspec 'GIF' do |gif| - gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DGIF_SUPPORT_ENABLED' } - - gif.dependency 'FLAnimatedImage', '~> 1.0' + gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DGIF_SUPPORT_ENABLED' } + gif.dependency 'FLAnimatedImage', '~> 1.0' end end From c2835ad2bcd78bb267008741f1809ee47f81d58a Mon Sep 17 00:00:00 2001 From: Storix Date: Sun, 10 Apr 2016 12:41:57 +0300 Subject: [PATCH 13/21] Revert line paddings to the original state --- .../CTAssetCollectionViewController.m | 1 - CTAssetsPickerController/CTAssetItemViewController.m | 12 +++++++++--- CTAssetsPickerController/CTAssetScrollView.m | 6 ++++-- .../CTAssetsGridViewController.h | 1 - .../CTAssetsPageViewController.m | 4 ++-- CTAssetsPickerController/CTAssetsPickerController.m | 1 - CTAssetsPickerDemo/CTMasterViewController.m | 2 -- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CTAssetsPickerController/CTAssetCollectionViewController.m b/CTAssetsPickerController/CTAssetCollectionViewController.m index 9d34941a..0daf3c61 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewController.m +++ b/CTAssetsPickerController/CTAssetCollectionViewController.m @@ -68,7 +68,6 @@ - (instancetype)init if (self = [super initWithStyle:UITableViewStylePlain]) { _imageManager = [PHCachingImageManager new]; - [self addNotificationObserver]; } diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 24dfe763..e1f42a02 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal */ + #import #import "CTAssetsPickerController.h" #import "CTAssetItemViewController.h" @@ -33,6 +34,8 @@ of this software and associated documentation files (the "Software"), to deal #import "PHImageManager+CTAssetsPickerController.h" + + @interface CTAssetItemViewController () @property (nonatomic, weak) CTAssetsPickerController *picker; @@ -50,6 +53,9 @@ @interface CTAssetItemViewController () @end + + + @implementation CTAssetItemViewController + (CTAssetItemViewController *)assetItemViewControllerForAsset:(PHAsset *)asset @@ -136,7 +142,7 @@ - (void)setupViews { CTAssetScrollView *scrollView = [CTAssetScrollView newAutoLayoutView]; scrollView.allowsSelection = self.allowsSelection; - + self.scrollView = scrollView; [self.view addSubview:self.scrollView]; [self.view layoutIfNeeded]; @@ -202,7 +208,7 @@ - (void)requestAssetImage // this image is set for transition animation self.image = image; - + dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = info[PHImageErrorKey]; @@ -231,7 +237,7 @@ - (PHImageRequestOptions *)imageRequestOptions [self.scrollView setProgress:progress]; }); }; - + return options; } diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 0e1fb54c..5ad9b9a1 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -24,7 +24,6 @@ of this software and associated documentation files (the "Software"), to deal */ - #import #import "CTAssetScrollView.h" #import "CTAssetPlayButton.h" @@ -33,6 +32,8 @@ of this software and associated documentation files (the "Software"), to deal #import "UIImage+CTAssetsPickerController.h" + + NSString * const CTAssetScrollViewDidTapNotification = @"CTAssetScrollViewDidTapNotification"; NSString * const CTAssetScrollViewPlayerWillPlayNotification = @"CTAssetScrollViewPlayerWillPlayNotification"; NSString * const CTAssetScrollViewPlayerWillPauseNotification = @"CTAssetScrollViewPlayerWillPauseNotification"; @@ -289,7 +290,7 @@ - (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary * self.playButton.hidden = [asset ctassetsPickerIsPhoto]; BOOL isDegraded = [info[PHImageResultIsDegradedKey] boolValue]; - + if (self.image == nil || !isDegraded) { BOOL zoom = (!self.image); @@ -347,6 +348,7 @@ - (void)unbindPlayerItem } + #pragma mark - Upate zoom scales - (void)updateZoomScalesAndZoom:(BOOL)zoom diff --git a/CTAssetsPickerController/CTAssetsGridViewController.h b/CTAssetsPickerController/CTAssetsGridViewController.h index a2cf7842..34d68fec 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.h +++ b/CTAssetsPickerController/CTAssetsGridViewController.h @@ -45,7 +45,6 @@ @property (nonatomic, weak) id delegate; @property (nonatomic, strong, nonnull) PHAssetCollection *assetCollection; - @end diff --git a/CTAssetsPickerController/CTAssetsPageViewController.m b/CTAssetsPickerController/CTAssetsPageViewController.m index 67044dcd..68382706 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.m +++ b/CTAssetsPickerController/CTAssetsPageViewController.m @@ -205,7 +205,7 @@ - (void)setPageIndex:(NSInteger)pageIndex CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:asset]; page.allowsSelection = self.allowsSelection; - + [self setViewControllers:@[page] direction:UIPageViewControllerNavigationDirectionForward animated:NO @@ -234,7 +234,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl PHAsset *beforeAsset = self.assets[(index - 1)]; CTAssetItemViewController *page = [CTAssetItemViewController assetItemViewControllerForAsset:beforeAsset]; page.allowsSelection = self.allowsSelection; - + return page; } diff --git a/CTAssetsPickerController/CTAssetsPickerController.m b/CTAssetsPickerController/CTAssetsPickerController.m index 0f514595..7e055593 100644 --- a/CTAssetsPickerController/CTAssetsPickerController.m +++ b/CTAssetsPickerController/CTAssetsPickerController.m @@ -249,7 +249,6 @@ - (void)setupEmptyViewController - (void)setupSplitViewController { CTAssetCollectionViewController *vc = [CTAssetCollectionViewController new]; - CTAssetsNavigationController *master = [[CTAssetsNavigationController alloc] initWithRootViewController:vc]; UINavigationController *detail = [self emptyNavigationController]; UISplitViewController *svc = [UISplitViewController new]; diff --git a/CTAssetsPickerDemo/CTMasterViewController.m b/CTAssetsPickerDemo/CTMasterViewController.m index 3fb1b4a9..b09c11eb 100644 --- a/CTAssetsPickerDemo/CTMasterViewController.m +++ b/CTAssetsPickerDemo/CTMasterViewController.m @@ -166,7 +166,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (row == 5) title = @"UI tweaks"; - } if (section == 1) @@ -242,7 +241,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (row == 5) vc = (UIViewController *)[CTUITweaksViewController new]; - } if (section == 1) From 2bcc567945e78dbb6e1e792615ac6c351cd4ad08 Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:09:58 +0300 Subject: [PATCH 14/21] Change dependency to YYImage in podspec --- CTAssetsPickerController.podspec | 2 +- Podfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index dfa07bdc..e1cf771c 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -36,6 +36,6 @@ Pod::Spec.new do |spec| # subspec for GIF plugin. spec.subspec 'GIF' do |gif| gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DGIF_SUPPORT_ENABLED' } - gif.dependency 'FLAnimatedImage', '~> 1.0' + gif.dependency 'YYImage' end end diff --git a/Podfile.lock b/Podfile.lock index de3ed72a..5ff495a4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -14,7 +14,7 @@ EXTERNAL SOURCES: :path: "." SPEC CHECKSUMS: - CTAssetsPickerController: 23d8b23613c90d136a6e0e2f2b168c64af7271f5 + CTAssetsPickerController: b88d1ca098a4645399ab25e96b56b7b64550f2e7 PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb COCOAPODS: 0.39.0 From 7bfb101d15d6fe2fd8f69bc0392a1ee99490aa0b Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:23:20 +0300 Subject: [PATCH 15/21] Change type in accordance with the new YYImage lib --- CTAssetsPickerController/CTAssetItemViewController.m | 9 +++------ CTAssetsPickerController/CTAssetScrollView.h | 4 +--- CTAssetsPickerController/CTAssetScrollView.m | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index e1f42a02..01a9c0f1 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -266,16 +266,13 @@ - (void)requestAssetAnimatedImage { } else { - CTAssetAnimatedImage *image; + YYImage *animatedImage = [YYImage imageWithData:imageData]; - FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; - - image = [[CTAssetAnimatedImage alloc]initWithAnimatedImage:animatedImage]; - self.image = image; + self.image = animatedImage; dispatch_async(dispatch_get_main_queue(), ^{ - [self.scrollView bind:self.asset image:image requestInfo:info]; + [self.scrollView bind:self.asset image:animatedImage requestInfo:info]; }); } }]; diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index 70bd13c1..f0a72da2 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -32,9 +32,7 @@ #ifdef GIF_SUPPORT_ENABLED #import - -#import "FLAnimatedImage.h" -#import "CTAssetAnimatedImage.h" +#import "YYImage.h" #endif diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 5ad9b9a1..0da9f8c6 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -53,8 +53,8 @@ @interface CTAssetScrollView () @property (nonatomic, assign) CGFloat perspectiveZoomScale; #ifdef GIF_SUPPORT_ENABLED - // FLAnimatedImageView is a subclass of UIImageView with support for playing GIFs - @property (nonatomic, strong) FLAnimatedImageView *imageView; + // YYAnimatedImageView is a subclass of UIImageView with support for playing GIFs + @property (nonatomic, strong) YYAnimatedImageView *imageView; #else @property (nonatomic, strong) UIImageView *imageView; #endif @@ -110,7 +110,7 @@ - (void)dealloc - (void)setupViews { #ifdef GIF_SUPPORT_ENABLED - FLAnimatedImageView *imageView = [FLAnimatedImageView new]; + YYAnimatedImageView *imageView = [YYAnimatedImageView new]; #else UIImageView *imageView = [UIImageView new]; #endif From 3078f47f22aed30f3f73e50c866d809bc666d487 Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:37:57 +0300 Subject: [PATCH 16/21] Remove unnecessary conditional check --- CTAssetsPickerController/CTAssetScrollView.m | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 0da9f8c6..097826d7 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -296,15 +296,9 @@ - (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary * BOOL zoom = (!self.image); self.image = image; -#ifdef GIF_SUPPORT_ENABLED - if([image isKindOfClass:[CTAssetAnimatedImage class]]) - [(FLAnimatedImageView *)self.imageView setAnimatedImage: [(CTAssetAnimatedImage *)image animatedImage]]; - else - self.imageView.image = image; -#else self.imageView.image = image; -#endif - if (isDegraded) + + if (isDegraded) [self mimicProgress]; else [self setProgress:1]; From b325c2a02dc52f40ca98b031ef02f57b065b0d8c Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:39:28 +0300 Subject: [PATCH 17/21] Remove deprecated CTAssetAnimatedImage class --- .../CTAssetAnimatedImage.h | 55 ------------------- .../CTAssetAnimatedImage.m | 45 --------------- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 4 -- 3 files changed, 104 deletions(-) delete mode 100644 CTAssetsPickerController/CTAssetAnimatedImage.h delete mode 100644 CTAssetsPickerController/CTAssetAnimatedImage.m diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.h b/CTAssetsPickerController/CTAssetAnimatedImage.h deleted file mode 100644 index 6b0f7770..00000000 --- a/CTAssetsPickerController/CTAssetAnimatedImage.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - - MIT License (MIT) - - Copyright (c) 2016 Clement CN Tsang - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - */ - -#ifdef GIF_SUPPORT_ENABLED - -#import -#import - - -/** - * A wrapper class around FLAnimatedImage for using it as a drop-in replacement for UIImage - */ -@interface CTAssetAnimatedImage : UIImage - -/** - * Original animated image this class was initialized with. - */ -@property (nonnull, nonatomic, readonly) FLAnimatedImage *animatedImage; - - -/** - * Initializes a wrapper with an animated image. - * - * @param animatedImage An animated image (GIF) represented by the FLAnimatedImage instance. - * - * @return An instance of `CTAssetAnimatedImage` associated with an animated image. - */ -- (nonnull instancetype)initWithAnimatedImage:(nonnull FLAnimatedImage *)animatedImage NS_DESIGNATED_INITIALIZER; - -@end - -#endif diff --git a/CTAssetsPickerController/CTAssetAnimatedImage.m b/CTAssetsPickerController/CTAssetAnimatedImage.m deleted file mode 100644 index fda19cc1..00000000 --- a/CTAssetsPickerController/CTAssetAnimatedImage.m +++ /dev/null @@ -1,45 +0,0 @@ -/* - - MIT License (MIT) - - Copyright (c) 2016 Clement CN Tsang - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - - */ - -#ifdef GIF_SUPPORT_ENABLED - -#import "CTAssetAnimatedImage.h" - -@implementation CTAssetAnimatedImage - -- (instancetype)initWithAnimatedImage:(FLAnimatedImage *)animatedImage -{ - // this instance can be used itself as a poster image - if (self = [super initWithCGImage:animatedImage.posterImage.CGImage]) { - _animatedImage = animatedImage; - } - - return self; -} - -@end - -#endif diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index 4d0e2dd6..94d2881b 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -36,8 +36,6 @@ 0B3423A61CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PHImageManager+CTAssetsPickerController.h"; sourceTree = ""; }; 0B3423A71CB6E9C7003509E0 /* PHImageManager+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PHImageManager+CTAssetsPickerController.m"; sourceTree = ""; }; 408BD0916F5C7C71C93D0E93 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; - 6E4EBEEF1CB981E100A062BA /* CTAssetAnimatedImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTAssetAnimatedImage.h; sourceTree = ""; }; - 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTAssetAnimatedImage.m; sourceTree = ""; }; 969CB85D1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LaunchScreen.strings; sourceTree = ""; }; 969CB85E1C9C3ADF002687B5 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA21B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LaunchScreen.strings; sourceTree = ""; }; @@ -293,8 +291,6 @@ ADD965F21AAD5780002A26A2 /* CTAssetsPickerController */ = { isa = PBXGroup; children = ( - 6E4EBEEF1CB981E100A062BA /* CTAssetAnimatedImage.h */, - 6E4EBEF01CB981E100A062BA /* CTAssetAnimatedImage.m */, ADD9660D1AAD5780002A26A2 /* CTAssetsPickerController.h */, ADD9660E1AAD5780002A26A2 /* CTAssetsPickerController.m */, AD30D7FB1AAEE01800C79E3D /* CTAssetThumbnailView.h */, From 0795f7aa30b13101eaa9a012f74125da9a01f540 Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:43:44 +0300 Subject: [PATCH 18/21] Rename GIF dependency compilation flag to CTASSETS_GIF_ENABLED --- CTAssetsPickerController.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CTAssetsPickerController.podspec b/CTAssetsPickerController.podspec index e1cf771c..8ac2135d 100644 --- a/CTAssetsPickerController.podspec +++ b/CTAssetsPickerController.podspec @@ -35,7 +35,7 @@ Pod::Spec.new do |spec| # subspec for GIF plugin. spec.subspec 'GIF' do |gif| - gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DGIF_SUPPORT_ENABLED' } + gif.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DCTASSETS_GIF_ENABLED' } gif.dependency 'YYImage' end end From 534b3326e242b3561228ebd57654ccba4bfaf1fb Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:46:07 +0300 Subject: [PATCH 19/21] Rename preprocessor macro in accordance with new compilation flag --- CTAssetsPickerController/CTAssetItemViewController.m | 4 ++-- CTAssetsPickerController/CTAssetScrollView.h | 2 +- CTAssetsPickerController/CTAssetScrollView.m | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CTAssetsPickerController/CTAssetItemViewController.m b/CTAssetsPickerController/CTAssetItemViewController.m index 01a9c0f1..08addb97 100644 --- a/CTAssetsPickerController/CTAssetItemViewController.m +++ b/CTAssetsPickerController/CTAssetItemViewController.m @@ -87,7 +87,7 @@ - (void)viewWillAppear:(BOOL)animated [super viewWillAppear:animated]; [self setupScrollViewButtons]; -#ifdef GIF_SUPPORT_ENABLED +#ifdef CTASSETS_GIF_ENABLED // Get resource objects that describe the data files that an asset represents. NSArray *assetResources = [PHAssetResource assetResourcesForAsset: self.asset]; @@ -241,7 +241,7 @@ - (PHImageRequestOptions *)imageRequestOptions return options; } -#ifdef GIF_SUPPORT_ENABLED +#ifdef CTASSETS_GIF_ENABLED #pragma mark - Request animated image diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index f0a72da2..af290c3d 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -29,7 +29,7 @@ #import "CTAssetPlayButton.h" #import "CTAssetSelectionButton.h" -#ifdef GIF_SUPPORT_ENABLED +#ifdef CTASSETS_GIF_ENABLED #import #import "YYImage.h" diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index 097826d7..d3b8f3ab 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -52,7 +52,7 @@ @interface CTAssetScrollView () @property (nonatomic, assign) CGFloat perspectiveZoomScale; -#ifdef GIF_SUPPORT_ENABLED +#ifdef CTASSETS_GIF_ENABLED // YYAnimatedImageView is a subclass of UIImageView with support for playing GIFs @property (nonatomic, strong) YYAnimatedImageView *imageView; #else @@ -109,7 +109,7 @@ - (void)dealloc - (void)setupViews { -#ifdef GIF_SUPPORT_ENABLED +#ifdef CTASSETS_GIF_ENABLED YYAnimatedImageView *imageView = [YYAnimatedImageView new]; #else UIImageView *imageView = [UIImageView new]; From d44b5fb4e5d385cc750d71a6f10c188b229db01c Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 19:56:14 +0300 Subject: [PATCH 20/21] Change YYImage header to modular type --- CTAssetsPickerController/CTAssetScrollView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CTAssetsPickerController/CTAssetScrollView.h b/CTAssetsPickerController/CTAssetScrollView.h index af290c3d..33e64066 100644 --- a/CTAssetsPickerController/CTAssetScrollView.h +++ b/CTAssetsPickerController/CTAssetScrollView.h @@ -32,7 +32,7 @@ #ifdef CTASSETS_GIF_ENABLED #import -#import "YYImage.h" +#import "YYImage/YYImage.h" #endif From 68f6f6be7d2580982f1633115acea0f6111f9116 Mon Sep 17 00:00:00 2001 From: Storix Date: Thu, 21 Apr 2016 20:12:46 +0300 Subject: [PATCH 21/21] Improve consistency with the original code --- CTAssetsPickerController/CTAssetScrollView.m | 7 +++---- CTAssetsPickerDemo.xcodeproj/project.pbxproj | 2 +- Podfile.lock | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CTAssetsPickerController/CTAssetScrollView.m b/CTAssetsPickerController/CTAssetScrollView.m index d3b8f3ab..7f802c06 100644 --- a/CTAssetsPickerController/CTAssetScrollView.m +++ b/CTAssetsPickerController/CTAssetScrollView.m @@ -295,10 +295,9 @@ - (void)bind:(PHAsset *)asset image:(UIImage *)image requestInfo:(NSDictionary * { BOOL zoom = (!self.image); self.image = image; - - self.imageView.image = image; - - if (isDegraded) + self.imageView.image = image; + + if (isDegraded) [self mimicProgress]; else [self setProgress:1]; diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index 94d2881b..21bfb175 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -135,7 +135,7 @@ ADD966021AAD5780002A26A2 /* CTAssetItemViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetItemViewController.h; sourceTree = ""; }; ADD966031AAD5780002A26A2 /* CTAssetItemViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetItemViewController.m; sourceTree = ""; }; ADD966041AAD5780002A26A2 /* CTAssetScrollView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetScrollView.h; sourceTree = ""; }; - ADD966051AAD5780002A26A2 /* CTAssetScrollView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetScrollView.m; sourceTree = ""; }; + ADD966051AAD5780002A26A2 /* CTAssetScrollView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetScrollView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; ADD966061AAD5780002A26A2 /* CTAssetCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetCollectionViewCell.h; sourceTree = ""; }; ADD966071AAD5780002A26A2 /* CTAssetCollectionViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetCollectionViewCell.m; sourceTree = ""; }; ADD966081AAD5780002A26A2 /* CTAssetCollectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetCollectionViewController.h; sourceTree = ""; }; diff --git a/Podfile.lock b/Podfile.lock index 5ff495a4..5c22eb9c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -14,7 +14,7 @@ EXTERNAL SOURCES: :path: "." SPEC CHECKSUMS: - CTAssetsPickerController: b88d1ca098a4645399ab25e96b56b7b64550f2e7 + CTAssetsPickerController: d0e938e161a59cddf159621371c1be220a7d4b05 PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb COCOAPODS: 0.39.0