Skip to content
Browse files

* Added and completed the layer transition sample

  • Loading branch information...
1 parent 661c4cd commit 017137fc155050a0084d4c04d0454558fb73c867 @neror neror committed Sep 14, 2009
View
8 CA360.xcodeproj/project.pbxproj
@@ -19,6 +19,8 @@
DF8014A31038D12900B48250 /* CALayer+FTDebugDrawing.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8014A11038D12900B48250 /* CALayer+FTDebugDrawing.m */; };
DF8015621038E1C400B48250 /* LayerTransforms.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8015611038E1C400B48250 /* LayerTransforms.m */; };
DF8015631038E1C400B48250 /* LayerTransforms.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8015611038E1C400B48250 /* LayerTransforms.m */; };
+ DFAFBACF105EFF4200AE6FF1 /* LayerTransitions.m in Sources */ = {isa = PBXBuildFile; fileRef = DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */; };
+ DFAFBAD0105EFF4200AE6FF1 /* LayerTransitions.m in Sources */ = {isa = PBXBuildFile; fileRef = DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */; };
DFF70C321039D8BC0052EE6A /* ImageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70C311039D8BC0052EE6A /* ImageContent.m */; };
DFF70C331039D8BC0052EE6A /* ImageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70C311039D8BC0052EE6A /* ImageContent.m */; };
DFF70C461039D9E60052EE6A /* FTSLogo.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70C451039D9E60052EE6A /* FTSLogo.png */; };
@@ -100,6 +102,8 @@
DF8014A11038D12900B48250 /* CALayer+FTDebugDrawing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "CALayer+FTDebugDrawing.m"; path = "Classes/CALayer+FTDebugDrawing.m"; sourceTree = "<group>"; };
DF8015601038E1C400B48250 /* LayerTransforms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerTransforms.h; path = Classes/Samples/LayerTransforms.h; sourceTree = "<group>"; };
DF8015611038E1C400B48250 /* LayerTransforms.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayerTransforms.m; path = Classes/Samples/LayerTransforms.m; sourceTree = "<group>"; };
+ DFAFBACD105EFF4200AE6FF1 /* LayerTransitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerTransitions.h; path = Classes/Samples/LayerTransitions.h; sourceTree = "<group>"; };
+ DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayerTransitions.m; path = Classes/Samples/LayerTransitions.m; sourceTree = "<group>"; };
DFF70C301039D8BC0052EE6A /* ImageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ImageContent.h; path = Classes/Samples/ImageContent.h; sourceTree = "<group>"; };
DFF70C311039D8BC0052EE6A /* ImageContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImageContent.m; path = Classes/Samples/ImageContent.m; sourceTree = "<group>"; };
DFF70C451039D9E60052EE6A /* FTSLogo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FTSLogo.png; sourceTree = "<group>"; };
@@ -286,6 +290,8 @@
DFF7F659103634C70067ED5B /* KeyframeAnimation.m */,
DFF70D9C103A104C0052EE6A /* LayerActions.h */,
DFF70D9D103A104C0052EE6A /* LayerActions.m */,
+ DFAFBACD105EFF4200AE6FF1 /* LayerTransitions.h */,
+ DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */,
);
name = Animation;
sourceTree = "<group>";
@@ -467,6 +473,7 @@
DFF70D9E103A104C0052EE6A /* LayerActions.m in Sources */,
DFF70DA2103A10870052EE6A /* AnimationTransactions.m in Sources */,
DFF70DC0103A11DF0052EE6A /* AnimationGroups.m in Sources */,
+ DFAFBACF105EFF4200AE6FF1 /* LayerTransitions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -492,6 +499,7 @@
DFF70D9F103A104C0052EE6A /* LayerActions.m in Sources */,
DFF70DA3103A10870052EE6A /* AnimationTransactions.m in Sources */,
DFF70DC1103A11DF0052EE6A /* AnimationGroups.m in Sources */,
+ DFAFBAD0105EFF4200AE6FF1 /* LayerTransitions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 Classes/Samples/ImageContent.m
@@ -43,6 +43,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)dealloc {
FTRELEASE(simpleLayer_);
FTRELEASE(moneyLayer_);
+ FTRELEASE(magicButton_);
[super dealloc];
}
@@ -70,6 +71,7 @@ - (void)loadView {
- (void)viewDidUnload {
FTRELEASE(simpleLayer_);
FTRELEASE(moneyLayer_);
+ FTRELEASE(magicButton_);
}
#pragma mark View drawing
View
38 Classes/Samples/LayerTransitions.h
@@ -0,0 +1,38 @@
+/*
+ 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 <UIKit/UIKit.h>
+
+
+@interface LayerTransitions : UIViewController {
+ CALayer *containerLayer_;
+ CALayer *blueLayer_;
+ CALayer *redLayer_;
+
+ UIButton *transitionButton_;
+ UISegmentedControl *typeSelectControl_;
+ UISegmentedControl *subtypeSelectControl_;
+}
+
+@end
View
163 Classes/Samples/LayerTransitions.m
@@ -0,0 +1,163 @@
+/*
+ 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 "LayerTransitions.h"
+#import <QuartzCore/QuartzCore.h>
+
+@implementation LayerTransitions
+
++ (NSString *)friendlyName {
+ return @"Layer Transitions";
+}
+
+#pragma mark init and dealloc
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
+ if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
+ self.title = [[self class] friendlyName];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ FTRELEASE(containerLayer_);
+ FTRELEASE(blueLayer_);
+ FTRELEASE(redLayer_);
+ FTRELEASE(transitionButton_);
+ FTRELEASE(typeSelectControl_);
+ FTRELEASE(subtypeSelectControl_);
+ [super dealloc];
+}
+
+#pragma mark Load and unload the view
+
+- (void)loadView {
+ UIView *myView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+ myView.backgroundColor = [UIColor grayColor];
+
+ NSArray *typeItems = [NSArray arrayWithObjects:@"Push", @"Move In", @"Reveal", @"Fade", nil];
+ typeSelectControl_ = [[UISegmentedControl alloc] initWithItems:typeItems];
+ typeSelectControl_.frame = CGRectMake(10.f, 10.f, 300.f, 44.f);
+ typeSelectControl_.selectedSegmentIndex = 0;
+ [myView addSubview:typeSelectControl_];
+
+ NSArray *subtypeItems = [NSArray arrayWithObjects:@"Right", @"Left", @"Top", @"Bottom", nil];
+ subtypeSelectControl_ = [[UISegmentedControl alloc] initWithItems:subtypeItems];
+ subtypeSelectControl_.frame = CGRectMake(10.f, 60.f, 300.f, 44.f);
+ subtypeSelectControl_.selectedSegmentIndex = 0;
+ [myView addSubview:subtypeSelectControl_];
+
+ transitionButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
+ transitionButton_.frame = CGRectMake(10.f, 110.f, 300.f, 44.f);
+ [transitionButton_ setTitle:@"Start Transition" forState:UIControlStateNormal];
+ [transitionButton_ addTarget:self action:@selector(toggleTransition:) forControlEvents:UIControlEventTouchUpInside];
+ [myView addSubview:transitionButton_];
+
+
+ blueLayer_ = [[CALayer layer] retain];
+ redLayer_ = [[CALayer layer] retain];
+ containerLayer_ = [[CALayer layer] retain];
+
+ [myView.layer addSublayer:containerLayer_];
+ [containerLayer_ addSublayer:blueLayer_];
+ [containerLayer_ addSublayer:redLayer_];
+ self.view = myView;
+}
+
+- (void)viewDidUnload {
+ FTRELEASE(containerLayer_);
+ FTRELEASE(blueLayer_);
+ FTRELEASE(redLayer_);
+ FTRELEASE(transitionButton_);
+ FTRELEASE(typeSelectControl_);
+ FTRELEASE(subtypeSelectControl_);
+}
+
+#pragma mark View drawing
+
+- (void)viewWillAppear:(BOOL)animated {
+ CGRect rect = CGRectMake(0.f, 0.f, 240.f, 240.f);
+
+ containerLayer_.backgroundColor = [[UIColor clearColor] CGColor];
+ containerLayer_.bounds = rect;
+ containerLayer_.position = CGPointMake(160.f, 280.f);
+ [containerLayer_ setNeedsDisplay];
+
+ redLayer_.backgroundColor = [UIColorFromRGBA(0xFF0000, .75f) CGColor];
+ redLayer_.bounds = rect;
+ redLayer_.position = CGPointMake(120.f, 120.f);
+ redLayer_.hidden = YES;
+ [redLayer_ setNeedsDisplay];
+
+ blueLayer_.backgroundColor = [UIColorFromRGBA(0x0000FF, .75f) CGColor];
+ blueLayer_.bounds = rect;
+ blueLayer_.position = CGPointMake(120.f, 120.f);
+ [blueLayer_ setNeedsDisplay];
+}
+
+//- (void)viewDidAppear:(BOOL)animated {
+//
+//}
+
+#pragma mark Button Event Handlers
+
+- (void)toggleTransition:(id)sender {
+ CATransition *transition = [CATransition animation];
+ transition.duration = .5f;
+ transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ switch(typeSelectControl_.selectedSegmentIndex) {
+ case 0:
+ transition.type = kCATransitionPush;
+ break;
+ case 1:
+ transition.type = kCATransitionMoveIn;
+ break;
+ case 2:
+ transition.type = kCATransitionReveal;
+ break;
+ case 3:
+ transition.type = kCATransitionFade;
+ break;
+ }
+ switch(subtypeSelectControl_.selectedSegmentIndex) {
+ case 0:
+ transition.subtype = kCATransitionFromRight;
+ break;
+ case 1:
+ transition.subtype = kCATransitionFromLeft;
+ break;
+ case 2:
+ transition.subtype = kCATransitionFromTop;
+ break;
+ case 3:
+ transition.subtype = kCATransitionFromBottom;
+ break;
+ }
+
+ [containerLayer_ addAnimation:transition forKey:nil];
+ blueLayer_.hidden = !blueLayer_.hidden;
+ redLayer_.hidden = !redLayer_.hidden;
+}
+
+@end
View
4 Classes/Samples/SampleManager.m
@@ -37,6 +37,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "LayerActions.h"
#import "AnimationTransactions.h"
#import "AnimationGroups.h"
+#import "LayerTransitions.h"
@interface SampleManager ()
@@ -73,7 +74,8 @@ - (id)init {
NSArray *hier = [NSArray arrayWithObjects:[LayerTree class], nil];
NSArray *drawing = [NSArray arrayWithObjects:[ImageContent class], [LayerDrawing class], [StyleProperties class], nil];
NSArray *animation = [NSArray arrayWithObjects:[BasicAnimation class], [AnimationGroups class],
- [AnimationTransactions class], [KeyframeAnimation class], [LayerActions class], nil];
+ [AnimationTransactions class], [KeyframeAnimation class], [LayerActions class],
+ [LayerTransitions class], nil];
NSArray *special = [NSArray arrayWithObjects:[ShapeLayers class], [GradientLayers class], nil];

0 comments on commit 017137f

Please sign in to comment.
Something went wrong with that request. Please try again.