diff --git a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.pbxproj b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.pbxproj index f46b92c..c38d55c 100644 --- a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.pbxproj +++ b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.pbxproj @@ -125,6 +125,8 @@ C2B753F9199E88A9004BB1C3 /* UIImage+JM.m in Sources */ = {isa = PBXBuildFile; fileRef = C2B753F6199E88A9004BB1C3 /* UIImage+JM.m */; }; C2B753FC199E8AFE004BB1C3 /* JMTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C2B753FB199E8AFE004BB1C3 /* JMTableViewController.m */; }; C2B753FF199E8B81004BB1C3 /* JMTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C2B753FE199E8B81004BB1C3 /* JMTableViewCell.m */; }; + C2D0974319D6001000AA1980 /* JMAnimatedImageView+JMGif.m in Sources */ = {isa = PBXBuildFile; fileRef = C2D0974219D6001000AA1980 /* JMAnimatedImageView+JMGif.m */; }; + C2D0974419D6001000AA1980 /* JMAnimatedImageView+JMGif.m in Sources */ = {isa = PBXBuildFile; fileRef = C2D0974219D6001000AA1980 /* JMAnimatedImageView+JMGif.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -279,6 +281,8 @@ C2B753FB199E8AFE004BB1C3 /* JMTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMTableViewController.m; sourceTree = ""; }; C2B753FD199E8B81004BB1C3 /* JMTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMTableViewCell.h; sourceTree = ""; }; C2B753FE199E8B81004BB1C3 /* JMTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMTableViewCell.m; sourceTree = ""; }; + C2D0974119D6001000AA1980 /* JMAnimatedImageView+JMGif.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JMAnimatedImageView+JMGif.h"; sourceTree = ""; }; + C2D0974219D6001000AA1980 /* JMAnimatedImageView+JMGif.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JMAnimatedImageView+JMGif.m"; sourceTree = ""; }; C2EAE6E519C0241700B46A27 /* JMAnimatedLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JMAnimatedLog.h; sourceTree = ""; }; C2F4DB6B19BE5C4700F04261 /* JMAmimatedImageViewMacro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JMAmimatedImageViewMacro.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -531,6 +535,8 @@ C2F4DB6B19BE5C4700F04261 /* JMAmimatedImageViewMacro.h */, C2B753EF199E88A9004BB1C3 /* JMAnimatedImageView.h */, C2B753F0199E88A9004BB1C3 /* JMAnimatedImageView.m */, + C2D0974119D6001000AA1980 /* JMAnimatedImageView+JMGif.h */, + C2D0974219D6001000AA1980 /* JMAnimatedImageView+JMGif.m */, C2B03DFA19A52D000032B240 /* JMAnimatedImageView+Image.h */, C2B03DFB19A52D000032B240 /* JMAnimatedImageView+Image.m */, C2B753F1199E88A9004BB1C3 /* JMAnimationOperation.h */, @@ -739,6 +745,7 @@ C2B75333199E8802004BB1C3 /* main.m in Sources */, C2B7533D199E8802004BB1C3 /* JMViewController.m in Sources */, C2B03E0019A554E30032B240 /* JMFLViewController.m in Sources */, + C2D0974319D6001000AA1980 /* JMAnimatedImageView+JMGif.m in Sources */, C2954D1719A72C7600494F41 /* AppInformationsManager.m in Sources */, C2B03DFC19A52D000032B240 /* JMAnimatedImageView+Image.m in Sources */, C2B753F8199E88A9004BB1C3 /* JMAnimationOperation.m in Sources */, @@ -758,6 +765,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C2D0974419D6001000AA1980 /* JMAnimatedImageView+JMGif.m in Sources */, C2B75352199E8802004BB1C3 /* JMAnimatedImageViewTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.xcworkspace/xcuserdata/jeromemorissard.xcuserdatad/UserInterfaceState.xcuserstate b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.xcworkspace/xcuserdata/jeromemorissard.xcuserdatad/UserInterfaceState.xcuserstate index 42a1f9a..f7383c4 100644 Binary files a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.xcworkspace/xcuserdata/jeromemorissard.xcuserdatad/UserInterfaceState.xcuserstate and b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/project.xcworkspace/xcuserdata/jeromemorissard.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/xcuserdata/jeromemorissard.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/xcuserdata/jeromemorissard.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index fe2b454..8f94031 100644 --- a/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/xcuserdata/jeromemorissard.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/JMAnimatedImageView/JMAnimatedImageView.xcodeproj/xcuserdata/jeromemorissard.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,4 +2,16 @@ + + + + + + diff --git a/JMAnimatedImageView/JMAnimatedImageView/Base.lproj/Main.storyboard b/JMAnimatedImageView/JMAnimatedImageView/Base.lproj/Main.storyboard index 95cb82b..324d7db 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/Base.lproj/Main.storyboard +++ b/JMAnimatedImageView/JMAnimatedImageView/Base.lproj/Main.storyboard @@ -16,7 +16,7 @@ - + diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+Image.m b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+Image.m index 29f8c47..07f7d30 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+Image.m +++ b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+Image.m @@ -8,6 +8,7 @@ #import "JMAnimatedImageView+Image.h" #import "UIImage+JM.h" +#import "JMAnimatedImageView+JMGif.h" @implementation JMAnimatedImageView (Image) diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.h b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.h new file mode 100644 index 0000000..64e70df --- /dev/null +++ b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.h @@ -0,0 +1,39 @@ +// +// JMAnimatedImageView+JMGif.h +// JMAnimatedImageView +// +// Created by jerome morissard on 26/09/14. +// Copyright (c) 2014 jerome morissard. All rights reserved. +// + +#import "JMAnimatedImageView.h" +#import "JMGif.h" + +@interface JMAnimatedImageView (JMGif) + +//Specific to GIF +@property (strong, readonly, nonatomic) JMGif *gifObject; + +/** + * isAGifImageView + * + * @return BOOL + */ +- (BOOL)isAGifImageView; + +/** + * reloadAnimationImagesFromGifData:, This method reload a GIF image from a GIF NSData + * + * @param data NSData data + */ +- (void)reloadAnimationImagesFromGifData:(NSData *)data; + +/** + * reloadAnimationImagesFromGifNamed:, This method reload a GIF image from a GIF named + * + * @param gitName NSString gitName + */ +- (void)reloadAnimationImagesFromGifNamed:(NSString *)gitName; + + +@end diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.m b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.m new file mode 100644 index 0000000..8491dd2 --- /dev/null +++ b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.m @@ -0,0 +1,49 @@ +// +// JMAnimatedImageView+JMGif.m +// JMAnimatedImageView +// +// Created by jerome morissard on 26/09/14. +// Copyright (c) 2014 jerome morissard. All rights reserved. +// + +#import "JMAnimatedImageView+JMGif.h" +#import + +//JMGif *gifObject + +@implementation JMAnimatedImageView (JMGif) + +- (JMGif *)gifObject +{ + return objc_getAssociatedObject(self, _cmd); +} + +- (void)setGifObject:(JMGif *)gifObject +{ + objc_setAssociatedObject(self, @selector(gifObject), gifObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)isAGifImageView +{ + if (self.gifObject) { + return YES; + } + return NO; +} + +- (void)reloadAnimationImagesFromGifData:(NSData *)data +{ + self.gifObject = [[JMGif alloc] initWithData:data]; + self.animationDuration = JMDefaultGifDuration; + [self setCurrentIndex:0]; +} + +- (void)reloadAnimationImagesFromGifNamed:(NSString *)gitName +{ + self.gifObject = [JMGif gifNamed:gitName]; + self.animationDuration = JMDefaultGifDuration; + [self setCurrentIndex:0]; + [self updateGestures]; +} + +@end diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.h b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.h index f28e631..dc7a5a6 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.h +++ b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.h @@ -9,7 +9,6 @@ #import #import "JMOImageViewAnimationDelegate.h" #import "JMOImageViewAnimationDatasource.h" -#import "JMGif.h" #define JMDefaultGifDuration -1 @@ -42,6 +41,7 @@ typedef void (^JMCompletionFinishBlock)(BOOL resul); @property (assign, nonatomic) JMAnimatedImageViewMemoryOption memoryManagementOption; @property (assign, nonatomic) JMAnimatedImageViewOrder imageOrder; @property (assign, nonatomic) BOOL interactiveAnimation; +@property (nonatomic, assign) NSInteger currentIndex; /** * reloadAnimationImages, This method will call animationDatasource @@ -81,28 +81,6 @@ typedef void (^JMCompletionFinishBlock)(BOOL resul); */ - (void)animateToIndex:(NSInteger)index withDuration:(NSTimeInterval)duration withCompletionBlock:(JMCompletionFinishBlock)finishBlock; -//Specific to GIF -@property (strong, readonly, nonatomic) JMGif *gifObject; - -/** - * isAGifImageView - * - * @return BOOL - */ -- (BOOL)isAGifImageView; - -/** - * reloadAnimationImagesFromGifData:, This method reload a GIF image from a GIF NSData - * - * @param data NSData data - */ -- (void)reloadAnimationImagesFromGifData:(NSData *)data; - -/** - * reloadAnimationImagesFromGifNamed:, This method reload a GIF image from a GIF named - * - * @param gitName NSString gitName - */ -- (void)reloadAnimationImagesFromGifNamed:(NSString *)gitName; +- (void)updateGestures; @end diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.m b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.m index 67b3701..d74a7ed 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.m +++ b/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView.m @@ -11,6 +11,7 @@ #import "UIImage+JM.h" #import "JMAnimatedImageView+Image.h" #import "JMAnimatedLog.h" +#import "JMAnimatedImageView+JMGif.h" typedef NS_ENUM(NSUInteger, UIImageViewAnimationOption) { UIImageViewAnimationOptionLinear = 0, @@ -23,7 +24,6 @@ typedef NS_ENUM(NSUInteger, UIImageViewAnimationState) { }; @interface JMAnimatedImageView() -@property (nonatomic, assign) NSInteger currentIndex; @property (nonatomic, assign) NSInteger operationInQueue; @property (nonatomic, strong) NSOperationQueue *animationQueue; @property (nonatomic, strong) UIPanGestureRecognizer *panGesture; @@ -75,27 +75,12 @@ - (void)setup - (void)reloadAnimationImages { if ([self.animationDatasource respondsToSelector:@selector(firstIndexForAnimatedImageView:)]) { - [self setCurrentCardImageAtindex:[self.animationDatasource firstIndexForAnimatedImageView:self]]; + [self setCurrentIndex:[self.animationDatasource firstIndexForAnimatedImageView:self]]; } else { - [self setCurrentCardImageAtindex:0]; + [self setCurrentIndex:0]; } } -- (void)reloadAnimationImagesFromGifData:(NSData *)data -{ - _gifObject = [[JMGif alloc] initWithData:data]; - self.animationDuration = JMDefaultGifDuration; - [self setCurrentCardImageAtindex:0]; -} - -- (void)reloadAnimationImagesFromGifNamed:(NSString *)gitName -{ - _gifObject = [JMGif gifNamed:gitName]; - self.animationDuration = JMDefaultGifDuration; - [self setCurrentCardImageAtindex:0]; - [self updateGestures]; -} - - (BOOL)checkLifeCycleSanity { if (self.superview) { @@ -107,10 +92,17 @@ - (BOOL)checkLifeCycleSanity - (void)setCurrentIndex:(NSInteger)currentIndex { - _currentIndex = currentIndex; + NSInteger realIndex = [self realIndexForComputedIndex:currentIndex]; + + _currentIndex = realIndex; if ([self.animationDelegate respondsToSelector:@selector(imageView:didChangeCurrentindex:)]) { [self.animationDelegate imageView:self didChangeCurrentindex:_currentIndex]; } + + self.image = [self imageAtIndex:_currentIndex]; + if (self.animationType == JMAnimatedImageViewAnimationTypeManualSwipe) { + [self updatePageControl]; + } } - (void)setupTempImageViewAtOriginiX:(CGFloat)x @@ -140,14 +132,6 @@ - (void)setupTempImageViewAtOriginiX:(CGFloat)x #pragma mark - overided setter -- (BOOL)isAGifImageView -{ - if (_gifObject) { - return YES; - } - return NO; -} - - (void)setInteractiveAnimation:(BOOL)interactiveAnimation { _interactiveAnimation = interactiveAnimation; @@ -269,9 +253,9 @@ - (void)imageViewTouchedWithFollowingPanGesture:(UIPanGestureRecognizer *)gestur self.userInteractionEnabled = YES; if (finishSwipeEvent) { if (velocity.x > 0) { - [self setCurrentCardImageAtindex:[self realIndexForComputedIndex:self.currentIndex + 1]]; + [self setCurrentIndex:[self realIndexForComputedIndex:self.currentIndex + 1]]; } else { - [self setCurrentCardImageAtindex:[self realIndexForComputedIndex:self.currentIndex -1 ]]; + [self setCurrentIndex:[self realIndexForComputedIndex:self.currentIndex -1 ]]; } } }]; @@ -304,9 +288,9 @@ - (void)imageViewTouchedWithPanGesture:(UIPanGestureRecognizer *)gestureRecogniz NSInteger shift = abs(velocity.x) / (16 * [UIScreen mainScreen].scale * pointUnity); if(velocity.x > 0) { - [self setCurrentCardImageAtindex:index+(_imageOrder) * shift]; + [self setCurrentIndex:index+(_imageOrder) * shift]; } else { - [self setCurrentCardImageAtindex:index-(_imageOrder) * shift]; + [self setCurrentIndex:index-(_imageOrder) * shift]; } /* @@ -342,28 +326,6 @@ - (void)imageViewTouched:(UIGestureRecognizer *)gestureRecognizer #pragma mark - Load images -- (void)setCurrentCardImageAtindex:(NSInteger)index -{ - NSInteger realIndex = [self realIndexForComputedIndex:index]; - self.image = [self imageAtIndex:realIndex]; - self.currentIndex = realIndex; - - if (self.animationType == JMAnimatedImageViewAnimationTypeManualSwipe) { - [self updatePageControl]; - } -} - -- (void)setCurrentImage:(UIImage *)img forIndex:(NSInteger)index -{ - JMLog(@"%s index:%d",__FUNCTION__,(int)index); - NSInteger realIndex = [self realIndexForComputedIndex:index]; - self.image = img; - self.currentIndex = realIndex; - if (self.animationType == JMAnimatedImageViewAnimationTypeManualSwipe) { - [self updatePageControl]; - } -} - - (NSInteger)realIndexForComputedIndex:(NSInteger)index { NSInteger nb = [self numberOfImages]; @@ -389,6 +351,7 @@ - (void)moveCurrentCardImageFromIndex:(NSInteger)fromIndex withCompletionBlock:(JMCompletionFinishBlock)finishBlock { dispatch_async(self.animationManagementQueue, ^{ + NSTimeInterval unitDuration; NSInteger shiftUnit = shift / abs((int)shift); // 1 ou -1 @@ -476,7 +439,7 @@ - (void)changeImageToIndex:(NSInteger)index withTimeInterval:(NSTimeInterval)dur } completion:^(BOOL finished) { [self.tempSwapedImageView removeFromSuperview]; - [self setCurrentCardImageAtindex:[self realIndexForComputedIndex:index]]; + [self setCurrentIndex:[self realIndexForComputedIndex:index]]; if (repeat) { [self changeImageToIndex:(self.currentIndex+1) withTimeInterval:duration repeat:repeat]; } @@ -557,7 +520,7 @@ - (void)startAnimating if (self.animationType == JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition) { if ([self isAGifImageView]) { [self moveCurrentCardImageFromIndex:self.currentIndex - shift:_gifObject.items.count + shift:self.gifObject.items.count withDuration:self.animationDuration animationOption:UIImageViewAnimationOptionLinear withCompletionBlock:NULL]; diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMFLViewController.m b/JMAnimatedImageView/JMAnimatedImageView/JMFLViewController.m index ccfe680..987c910 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/JMFLViewController.m +++ b/JMAnimatedImageView/JMAnimatedImageView/JMFLViewController.m @@ -8,6 +8,7 @@ #import "JMFLViewController.h" #import "JMAnimatedImageView.h" +#import "JMAnimatedImageView+JMGif.h" @interface JMFLViewController () @property (weak, nonatomic) IBOutlet JMAnimatedImageView *carImageView1; diff --git a/JMAnimatedImageView/JMAnimatedImageView/JMViewController.m b/JMAnimatedImageView/JMAnimatedImageView/JMViewController.m index 680db25..8b065fe 100644 --- a/JMAnimatedImageView/JMAnimatedImageView/JMViewController.m +++ b/JMAnimatedImageView/JMAnimatedImageView/JMViewController.m @@ -8,12 +8,12 @@ #import "JMViewController.h" #import "JMAnimatedImageView.h" +#import "JMAnimatedImageView+JMGif.h" @interface JMViewController () @property (weak, nonatomic) IBOutlet JMAnimatedImageView *carImageView; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (assign, nonatomic) JMAnimatedImageViewAnimationType animationType; - @end @implementation JMViewController @@ -79,10 +79,10 @@ - (void)viewDidLoad self.carImageView.hidden = NO; self.carImageView.animationDelegate = self; self.carImageView.animationDatasource = self; - self.carImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinear; + self.carImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition; self.carImageView.memoryManagementOption = JMAnimatedImageViewMemoryLoadImageLowMemoryUsage; self.carImageView.imageOrder = JMAnimatedImageViewOrderNormal; - self.carImageView.animationDuration = 1.0; + self.carImageView.animationDuration = 5.0; self.animationType = self.carImageView.animationType; [self.carImageView startAnimating]; @@ -96,7 +96,6 @@ - (void)viewDidLoad self.carImageView.animationType = JMAnimatedImageViewAnimationTypeInteractive; self.carImageView.memoryManagementOption = JMAnimatedImageViewMemoryLoadImageLowMemoryUsage; self.carImageView.imageOrder = JMAnimatedImageViewOrderReverse; - self.animationType = self.carImageView.animationType; [self.carImageView reloadAnimationImages];