-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
3 changed files
with
138 additions
and
0 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
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,41 @@ | ||
// | ||
// ILChoreography.h | ||
// Activity | ||
// | ||
// Created by ∞ on 02/10/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
#if TARGET_OS_IPHONE | ||
|
||
#import "ILActivity.h" | ||
#import <UIKit/UIKit.h> | ||
|
||
/* Choreographies are activities that handle a single- or multi-step UIKit animation. When started, they execute all animation and completion blocks in a UIView animation block. | ||
Since animation is complex, subclasses can override the -startAnimating method to set up the animation themselves. (This method is called by ILChoreography's -main.) Subclasses can then use the -invokePreparationBlocks, -invokeAnimationBlocks and -invokeCompletionBlocksWithResult: methods to invoke any added animation or completion blocks. You can also perform multiple, chained or parallel animations. No matter what you do, it's this method's responsibility to call -end after all blocks have been invoked. | ||
The default implementation runs animation blocks with the following settings: a duration of 0.25; ease-in-out easing; default options otherwise. The default implementation invokes completion blocks and calls -end when this animation ends. | ||
Choreographies may be cancelled like any other activity. However, the default implementation does NOT stop animations right away, as it overrides -cancel to do nothing. To implement cancelling in a subclass, override -cancel entirely without calling super. | ||
*/ | ||
@interface ILChoreography : ILActivity | ||
|
||
// All preparation blocks are invoked as the choreography begins, outside of an animation block. | ||
// All animation blocks are invoked within the UIView animation context. | ||
// All completion blocks are invoked as part of the UIView animation completion block, just before the activity ends. | ||
- (void) addAnimationWithBlocksForPreparing:(void(^)()) preparation animating:(void(^)()) animations completing:(void(^)(BOOL)) completion; | ||
|
||
// Subclasses only. | ||
- (void) cancel; // overridden to do nothing. overridable. | ||
- (void) startAnimating; // overridable. | ||
- (void) invokeAnimationBlocks; // in an arbitrary order | ||
- (void) invokePreparationBlocks; // in an arbitrary order | ||
- (void) invokeCompletionBlocksWithResult:(BOOL) finished; // in an arbitrary order | ||
|
||
@end | ||
|
||
#endif |
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,89 @@ | ||
// | ||
// ILChoreography.m | ||
// Activity | ||
// | ||
// Created by ∞ on 02/10/11. | ||
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "ILChoreography.h" | ||
|
||
#if TARGET_OS_IPHONE | ||
|
||
@implementation ILChoreography { | ||
NSMutableSet* animationBlocks, * completionBlocks, * preparationBlocks; | ||
} | ||
|
||
- (id)init; | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
animationBlocks = [NSMutableSet new]; | ||
completionBlocks = [NSMutableSet new]; | ||
preparationBlocks = [NSMutableSet new]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc; | ||
{ | ||
[animationBlocks release]; | ||
[completionBlocks release]; | ||
[preparationBlocks release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) addAnimationWithBlocksForPreparing:(void(^)()) preparation animating:(void(^)()) animations completing:(void(^)(BOOL)) completion; | ||
{ | ||
[animationBlocks addObject:[[animations copy] autorelease]]; | ||
[completionBlocks addObject:[[completion copy] autorelease]]; | ||
[preparationBlocks addObject:[[preparation copy] autorelease]]; | ||
} | ||
|
||
- (void)main; | ||
{ | ||
[self startAnimating]; | ||
} | ||
|
||
- (void)startAnimating; | ||
{ | ||
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ | ||
[self invokeAnimationBlocks]; | ||
} completion:^(BOOL finished) { | ||
[self invokeCompletionBlocksWithResult:finished]; | ||
[self end]; | ||
}]; | ||
} | ||
|
||
- (void)cancel; | ||
{ /* This method intentionally left blank */ } | ||
|
||
- (void) invokePreparationBlocks; // in an arbitrary order | ||
{ | ||
for (void (^block)() in preparationBlocks) | ||
block(); | ||
} | ||
|
||
- (void) invokeAnimationBlocks; // in an arbitrary order | ||
{ | ||
for (void (^block)() in animationBlocks) | ||
block(); | ||
} | ||
|
||
- (void)invokeCompletionBlocksWithResult:(BOOL)finished; | ||
{ | ||
for (void (^block)(BOOL) in completionBlocks) | ||
block(finished); | ||
} | ||
|
||
- (void)end; | ||
{ | ||
[animationBlocks removeAllObjects]; | ||
[completionBlocks removeAllObjects]; | ||
[preparationBlocks removeAllObjects]; | ||
} | ||
|
||
@end | ||
|
||
#endif |