Permalink
Browse files

Added example that shows animation chaining, target/action, and delay…

…ing animations.
  • Loading branch information...
1 parent 3a1b48d commit 9cb930924ff8ba3d9b52b034f09e18fb0c80ed11 @neror committed Apr 13, 2010
View
41 Examples/AnimationChaining.h
@@ -0,0 +1,41 @@
+/*
+ The MIT License
+
+ Copyright (c) 2009 Free Time Studios and Nathan Eror
+
+ 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 "ExampleManager.h"
+
+@interface AnimationChaining : UIViewController {
+ UIView *redView_;
+ UIView *greenView_;
+ UIView *blueView_;
+
+ UIButton *performAnimationButton_;
+}
+
+@property(nonatomic, retain) UIView *redView;
+@property(nonatomic, retain) UIView *blueView;
+@property(nonatomic, retain) UIView *greenView;
+
+@property(nonatomic,retain) UIButton *performAnimationButton;
+
+@end
View
130 Examples/AnimationChaining.m
@@ -0,0 +1,130 @@
+/*
+ The MIT License
+
+ Copyright (c) 2009 Free Time Studios and Nathan Eror
+
+ 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 "AnimationChaining.h"
+#import "FTAnimation.h"
+
+@implementation AnimationChaining
+
+@synthesize redView = redView_;
+@synthesize greenView = greenView_;
+@synthesize blueView = blueView_;
+
+@synthesize performAnimationButton = performAnimationButton_;
+
++ (NSString *)displayName {
+ return @"Animation Chaining";
+}
+
+#pragma mark init and dealloc
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
+ if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
+ self.title = [[self class] displayName];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ self.redView = nil;
+ self.greenView = nil;
+ self.blueView = nil;
+ self.performAnimationButton = nil;
+ [super dealloc];
+}
+
+
+#pragma mark Load and unload the view
+
+- (void)loadView {
+ self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+ self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Checkers.png"]];;
+
+ self.redView = [[[UIView alloc] initWithFrame:CGRectMake(10.f, 20.f, 300.f, 40.f)] autorelease];
+ self.redView.backgroundColor = [UIColor redColor];
+ self.redView.hidden = YES;
+ [self.view addSubview:self.redView];
+
+ self.greenView = [[[UIView alloc] initWithFrame:CGRectMake(10.f, 70.f, 300.f, 40.f)] autorelease];
+ self.greenView.backgroundColor = [UIColor greenColor];
+ self.greenView.hidden = YES;
+ [self.view addSubview:self.greenView];
+
+ self.blueView = [[[UIView alloc] initWithFrame:CGRectMake(10.f, 120.f, 300.f, 40.f)] autorelease];
+ self.blueView.backgroundColor = [UIColor blueColor];
+ self.blueView.hidden = YES;
+ [self.view addSubview:self.blueView];
+
+ self.performAnimationButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+ self.performAnimationButton.frame = CGRectMake(10., 356., 300., 44.);
+ [self.performAnimationButton setTitle:@"Run Animation" forState:UIControlStateNormal];
+ [self.performAnimationButton addTarget:self action:@selector(performAnimation:) forControlEvents:UIControlEventTouchUpInside];
+
+ [self.view addSubview:self.performAnimationButton];
+}
+
+#pragma mark Animation delegates
+
+- (void)redAnimationStopped:(CAAnimation *)anim finished:(BOOL)finished {
+ FTAnimationManager *animManager = [FTAnimationManager sharedManager];
+
+ CAAnimation *redOut = [animManager backOutAnimationFor:self.redView withFade:NO direction:kFTAnimationTop
+ duration:1.f delegate:nil startSelector:nil stopSelector:nil];
+
+ CAAnimation *greenOut = [animManager backOutAnimationFor:self.greenView withFade:NO direction:kFTAnimationTop
+ duration:.7f delegate:nil startSelector:nil stopSelector:nil];
+ greenOut = [animManager delayStartOfAnimation:greenOut withDelay:.3f];
+
+ CAAnimation *blueOut = [animManager backOutAnimationFor:self.blueView withFade:NO direction:kFTAnimationTop
+ duration:.4f delegate:nil startSelector:nil stopSelector:nil];
+ blueOut = [animManager delayStartOfAnimation:blueOut withDelay:.6f];
+
+ [CATransaction begin];
+ [self.redView.layer addAnimation:redOut forKey:nil];
+ [self.greenView.layer addAnimation:greenOut forKey:nil];
+ [self.blueView.layer addAnimation:blueOut forKey:nil];
+ [CATransaction commit];
+}
+
+#pragma mark Event Handlers
+
+- (void)performAnimation:(id)sender {
+ FTAnimationManager *animManager = [FTAnimationManager sharedManager];
+
+ CAAnimation *red = [animManager backInAnimationFor:self.redView withFade:NO
+ direction:kFTAnimationTop duration:.6f
+ delegate:nil startSelector:nil stopSelector:nil];
+ CAAnimation *green = [animManager backInAnimationFor:self.greenView withFade:NO
+ direction:kFTAnimationTop duration:.6f
+ delegate:nil startSelector:nil stopSelector:nil];
+ CAAnimation *blue = [animManager backInAnimationFor:self.blueView withFade:NO
+ direction:kFTAnimationTop duration:.6f
+ delegate:nil startSelector:nil stopSelector:nil];
+
+ [red setStopSelector:@selector(redAnimationStopped:finished:) withTarget:self];
+
+ [animManager chainAnimations:[NSArray arrayWithObjects:blue, green, red, nil] run:YES];
+}
+
+@end
View
8 Examples/ExampleManager.h
@@ -24,14 +24,6 @@
#import <Foundation/Foundation.h>
-@interface Example : UIViewController {
-}
-
-+ (NSString *)name;
-
-@end
-
-
@interface ExampleManager : NSObject {
NSArray *groups_;
NSArray *samples_;
View
5 Examples/ExampleManager.m
@@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "PopInOut.h"
#import "FallInOut.h"
#import "FlyOut.h"
+#import "AnimationChaining.h"
@interface ExampleManager ()
@@ -64,7 +65,7 @@ - (id)init {
self = [super init];
if (self != nil) {
groups_ = [[NSArray alloc] initWithObjects:@"Animating Single Views",
- @"Delegation and Animation Info",
+ @"Advanced Features",
nil];
samples_ = [[NSArray alloc] initWithObjects:[NSArray arrayWithObjects:[BackInOut class],
@@ -75,7 +76,7 @@ - (id)init {
[FallInOut class],
[FlyOut class],
nil],
- [NSArray array],
+ [NSArray arrayWithObject:[AnimationChaining class]],
nil];
}
return self;
View
2 Examples/FlyOut.m
@@ -20,7 +20,7 @@ of this software and associated documentation files (the "Software"), to deal
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 "FlyOut.h"
#import "FTAnimation.h"
View
20 FTUtils.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
AA747D9F0F9514B9006C5449 /* FTUtils_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* FTUtils_Prefix.pch */; };
+ DF16614D1174CAC700054B46 /* AnimationChaining.m in Sources */ = {isa = PBXBuildFile; fileRef = DF16614C1174CAC700054B46 /* AnimationChaining.m */; };
DF1E44EF10C29C1500F80FC0 /* FTAnimation+UIView.m in Sources */ = {isa = PBXBuildFile; fileRef = DF1E44EE10C29C1500F80FC0 /* FTAnimation+UIView.m */; };
DF1E44F010C29C1500F80FC0 /* FTAnimation+UIView.h in Headers */ = {isa = PBXBuildFile; fileRef = DF1E44ED10C29C1500F80FC0 /* FTAnimation+UIView.h */; };
DF1E44F110C29C1500F80FC0 /* FTAnimation+UIView.m in Sources */ = {isa = PBXBuildFile; fileRef = DF1E44EE10C29C1500F80FC0 /* FTAnimation+UIView.m */; };
@@ -76,6 +77,8 @@
/* Begin PBXFileReference section */
AA747D9E0F9514B9006C5449 /* FTUtils_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FTUtils_Prefix.pch; sourceTree = SOURCE_ROOT; };
D2AAC07E0554694100DB518D /* libFTUtils.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFTUtils.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ DF16614B1174CAC700054B46 /* AnimationChaining.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationChaining.h; sourceTree = "<group>"; };
+ DF16614C1174CAC700054B46 /* AnimationChaining.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimationChaining.m; sourceTree = "<group>"; };
DF19192010E2A94900906A0D /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
DF1E44ED10C29C1500F80FC0 /* FTAnimation+UIView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "FTAnimation+UIView.h"; path = "FTUtils/FTAnimation+UIView.h"; sourceTree = "<group>"; };
DF1E44EE10C29C1500F80FC0 /* FTAnimation+UIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FTAnimation+UIView.m"; sourceTree = "<group>"; };
@@ -263,16 +266,6 @@
DFFDB49110C2D91B00F7BF95 /* Examples */ = {
isa = PBXGroup;
children = (
- DFFDB4A510C2D9E300F7BF95 /* Simple View Animation */,
- DFFDB5BC10C2DDB600F7BF95 /* Supporting Classes */,
- DF3E064410C71181004434C3 /* Resources */,
- );
- path = Examples;
- sourceTree = "<group>";
- };
- DFFDB4A510C2D9E300F7BF95 /* Simple View Animation */ = {
- isa = PBXGroup;
- children = (
DFFDB59B10C2DC7900F7BF95 /* SimpleAnimationExample.h */,
DFFDB59C10C2DC7900F7BF95 /* SimpleAnimationExample.m */,
DFFDB5DE10C2DFB700F7BF95 /* BackInOut.h */,
@@ -289,8 +282,12 @@
DF3E073310C72689004434C3 /* FallInOut.m */,
DF3E075910C7278D004434C3 /* FlyOut.h */,
DF3E075A10C7278D004434C3 /* FlyOut.m */,
+ DF16614B1174CAC700054B46 /* AnimationChaining.h */,
+ DF16614C1174CAC700054B46 /* AnimationChaining.m */,
+ DFFDB5BC10C2DDB600F7BF95 /* Supporting Classes */,
+ DF3E064410C71181004434C3 /* Resources */,
);
- name = "Simple View Animation";
+ path = Examples;
sourceTree = "<group>";
};
DFFDB5BC10C2DDB600F7BF95 /* Supporting Classes */ = {
@@ -472,6 +469,7 @@
DF3E071410C72581004434C3 /* PopInOut.m in Sources */,
DF3E073410C72689004434C3 /* FallInOut.m in Sources */,
DF3E075B10C7278D004434C3 /* FlyOut.m in Sources */,
+ DF16614D1174CAC700054B46 /* AnimationChaining.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 9cb9309

Please sign in to comment.