-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0dedf68
commit 9ea9503
Showing
14 changed files
with
215 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.58 KB
(100%)
...project.xcworkspace/xcuserdata/jeromemorissard.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedGifImageView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// | ||
// JMAnimatedGifImageView.m | ||
// JMAnimatedImageView | ||
// | ||
// Created by jerome morissard on 01/10/14. | ||
// Copyright (c) 2014 jerome morissard. All rights reserved. | ||
// | ||
|
||
#import "JMAnimatedGifImageView.h" | ||
#import "JMAnimatedLog.h" | ||
#import "JMAnimationOperation.h" | ||
|
||
@implementation JMAnimatedGifImageView | ||
|
||
- (BOOL)isAGifImageView | ||
{ | ||
if (self.gifObject) { | ||
return YES; | ||
} | ||
return NO; | ||
} | ||
|
||
- (void)reloadAnimationImagesFromGifData:(NSData *)data | ||
{ | ||
_gifObject = [[JMGif alloc] initWithData:data]; | ||
self.animationDuration = JMDefaultGifDuration; | ||
[self setCurrentIndex:0]; | ||
} | ||
|
||
- (void)reloadAnimationImagesFromGifNamed:(NSString *)gitName | ||
{ | ||
_gifObject = [JMGif gifNamed:gitName]; | ||
self.animationDuration = JMDefaultGifDuration; | ||
[self setCurrentIndex:0]; | ||
[self updateGestures]; | ||
} | ||
|
||
- (void)moveCurrentCardImageFromIndex:(NSInteger)fromIndex | ||
shift:(NSInteger)shift | ||
withDuration:(NSTimeInterval)duration | ||
animationOption:(UIImageViewAnimationOption)option | ||
withCompletionBlock:(JMCompletionFinishBlock)finishBlock | ||
{ | ||
dispatch_async(self.animationManagementQueue, ^{ | ||
|
||
NSTimeInterval unitDuration; | ||
NSInteger shiftUnit = shift / abs((int)shift); // 1 ou -1 | ||
|
||
if (duration == JMDefaultGifDuration) { | ||
unitDuration = duration; | ||
|
||
} else { | ||
if (option == UIImageViewAnimationOptionLinear) { | ||
unitDuration = duration / abs((int)shift); | ||
} else { | ||
unitDuration = duration / abs((int)(shift * shift)); | ||
} | ||
} | ||
|
||
JMLog(@"%s fromIndex:%d shift:%d duration:%lf",__FUNCTION__,(int)fromIndex,(int)shift,duration); | ||
|
||
//[self cancelAnimations]; | ||
[self.animationQueue cancelAllOperations]; | ||
[self.animationQueue waitUntilAllOperationsAreFinished]; | ||
|
||
for (int i = 0; i < (int)abs((int)shift) ; i++) { | ||
|
||
NSInteger index = [self realIndexForComputedIndex:fromIndex+i*shiftUnit]; | ||
JMGifItem *item = [[self.gifObject items] objectAtIndex:index]; | ||
|
||
JMAnimationOperation *operation = [JMAnimationOperation animationOperationWithDuration:item.delayDuration | ||
completion:^(BOOL finished) | ||
{ | ||
|
||
if (self.animationType == JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition) { | ||
if ([self operationQueueIsFinished] == YES) { | ||
if (finishBlock) { | ||
finishBlock(YES); | ||
} | ||
|
||
if (self.animationRepeatCount == 0 && self.animationState == UIImageViewAnimationStateInPgrogress) { | ||
[self continueAnimating]; | ||
} | ||
} | ||
} | ||
}]; | ||
|
||
operation.animatedImageView = self; | ||
operation.imageIndex = index; | ||
[self.animationQueue addOperation:operation]; | ||
} | ||
}); | ||
} | ||
|
||
- (void)startAnimating | ||
{ | ||
self.animationState = UIImageViewAnimationStateInPgrogress; | ||
|
||
if ([self checkLifeCycleSanity] == NO) { | ||
return; | ||
} | ||
|
||
if (self.animationType == JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition) { | ||
[self moveCurrentCardImageFromIndex:self.currentIndex | ||
shift:self.gifObject.items.count | ||
withDuration:self.animationDuration | ||
animationOption:UIImageViewAnimationOptionLinear | ||
withCompletionBlock:NULL]; | ||
|
||
} else if (self.animationType == JMAnimatedImageViewAnimationTypeAutomaticLinear) { | ||
[self changeImageToIndex:(self.currentIndex + 1) withTimeInterval:self.animationDuration repeat:YES]; | ||
} | ||
} | ||
|
||
- (void)continueAnimating | ||
{ | ||
self.animationState = UIImageViewAnimationStateInPgrogress; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if ([self checkLifeCycleSanity] == NO) { | ||
return; | ||
} | ||
|
||
if ([self operationQueueIsFinished] == NO) { | ||
return; | ||
} | ||
|
||
[self moveCurrentCardImageFromIndex:self.currentIndex | ||
shift:self.gifObject.items.count | ||
withDuration:self.animationDuration | ||
animationOption:UIImageViewAnimationOptionLinear | ||
withCompletionBlock:NULL]; | ||
}); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView/JMAnimatedImageView+JMGif.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.