Permalink
Browse files

Added choreographies.

  • Loading branch information...
1 parent 64f5f89 commit 254712230f75f396b4a47a62c6f3a1cd2e875c49 @millenomi committed Oct 2, 2011
Showing with 138 additions and 0 deletions.
  1. +8 −0 Activity.xcodeproj/project.pbxproj
  2. +41 −0 Activity/ILChoreography.h
  3. +89 −0 Activity/ILChoreography.m
@@ -17,6 +17,8 @@
153BE590142E223600F475D8 /* ILActionSheetController.h in Headers */ = {isa = PBXBuildFile; fileRef = 153BE58E142E223500F475D8 /* ILActionSheetController.h */; };
153BE591142E223600F475D8 /* ILActionSheetController.m in Sources */ = {isa = PBXBuildFile; fileRef = 153BE58F142E223500F475D8 /* ILActionSheetController.m */; };
153BE5CA142E375100F475D8 /* ILAlertViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 153BE58B142E209F00F475D8 /* ILAlertViewController.m */; };
+ 158D70DD14388814004FA6B3 /* ILChoreography.h in Headers */ = {isa = PBXBuildFile; fileRef = 158D70DB14388814004FA6B3 /* ILChoreography.h */; };
+ 158D70DE14388814004FA6B3 /* ILChoreography.m in Sources */ = {isa = PBXBuildFile; fileRef = 158D70DC14388814004FA6B3 /* ILChoreography.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -32,6 +34,8 @@
153BE58B142E209F00F475D8 /* ILAlertViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ILAlertViewController.m; sourceTree = "<group>"; };
153BE58E142E223500F475D8 /* ILActionSheetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ILActionSheetController.h; sourceTree = "<group>"; };
153BE58F142E223500F475D8 /* ILActionSheetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ILActionSheetController.m; sourceTree = "<group>"; };
+ 158D70DB14388814004FA6B3 /* ILChoreography.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ILChoreography.h; sourceTree = "<group>"; };
+ 158D70DC14388814004FA6B3 /* ILChoreography.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ILChoreography.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -80,6 +84,8 @@
153BE584142CD05A00F475D8 /* ILActivity.h */,
153BE588142CE38300F475D8 /* ILActivity+Private.h */,
153BE585142CD05A00F475D8 /* ILActivity.m */,
+ 158D70DB14388814004FA6B3 /* ILChoreography.h */,
+ 158D70DC14388814004FA6B3 /* ILChoreography.m */,
153BE58A142E209F00F475D8 /* ILAlertViewController.h */,
153BE58B142E209F00F475D8 /* ILAlertViewController.m */,
153BE58E142E223500F475D8 /* ILActionSheetController.h */,
@@ -108,6 +114,7 @@
153BE589142CE38300F475D8 /* ILActivity+Private.h in Headers */,
153BE58C142E209F00F475D8 /* ILAlertViewController.h in Headers */,
153BE590142E223600F475D8 /* ILActionSheetController.h in Headers */,
+ 158D70DD14388814004FA6B3 /* ILChoreography.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -165,6 +172,7 @@
153BE587142CD05A00F475D8 /* ILActivity.m in Sources */,
153BE591142E223600F475D8 /* ILActionSheetController.m in Sources */,
153BE5CA142E375100F475D8 /* ILAlertViewController.m in Sources */,
+ 158D70DE14388814004FA6B3 /* ILChoreography.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -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
@@ -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

0 comments on commit 2547122

Please sign in to comment.