Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* Added and completed the layer transition sample

  • Loading branch information...
commit 017137fc155050a0084d4c04d0454558fb73c867 1 parent 661c4cd
Nathan Eror neror authored
8 CA360.xcodeproj/project.pbxproj
@@ -19,6 +19,8 @@
19 19 DF8014A31038D12900B48250 /* CALayer+FTDebugDrawing.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8014A11038D12900B48250 /* CALayer+FTDebugDrawing.m */; };
20 20 DF8015621038E1C400B48250 /* LayerTransforms.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8015611038E1C400B48250 /* LayerTransforms.m */; };
21 21 DF8015631038E1C400B48250 /* LayerTransforms.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8015611038E1C400B48250 /* LayerTransforms.m */; };
  22 + DFAFBACF105EFF4200AE6FF1 /* LayerTransitions.m in Sources */ = {isa = PBXBuildFile; fileRef = DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */; };
  23 + DFAFBAD0105EFF4200AE6FF1 /* LayerTransitions.m in Sources */ = {isa = PBXBuildFile; fileRef = DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */; };
22 24 DFF70C321039D8BC0052EE6A /* ImageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70C311039D8BC0052EE6A /* ImageContent.m */; };
23 25 DFF70C331039D8BC0052EE6A /* ImageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = DFF70C311039D8BC0052EE6A /* ImageContent.m */; };
24 26 DFF70C461039D9E60052EE6A /* FTSLogo.png in Resources */ = {isa = PBXBuildFile; fileRef = DFF70C451039D9E60052EE6A /* FTSLogo.png */; };
@@ -100,6 +102,8 @@
100 102 DF8014A11038D12900B48250 /* CALayer+FTDebugDrawing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "CALayer+FTDebugDrawing.m"; path = "Classes/CALayer+FTDebugDrawing.m"; sourceTree = "<group>"; };
101 103 DF8015601038E1C400B48250 /* LayerTransforms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerTransforms.h; path = Classes/Samples/LayerTransforms.h; sourceTree = "<group>"; };
102 104 DF8015611038E1C400B48250 /* LayerTransforms.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayerTransforms.m; path = Classes/Samples/LayerTransforms.m; sourceTree = "<group>"; };
  105 + DFAFBACD105EFF4200AE6FF1 /* LayerTransitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerTransitions.h; path = Classes/Samples/LayerTransitions.h; sourceTree = "<group>"; };
  106 + DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LayerTransitions.m; path = Classes/Samples/LayerTransitions.m; sourceTree = "<group>"; };
103 107 DFF70C301039D8BC0052EE6A /* ImageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ImageContent.h; path = Classes/Samples/ImageContent.h; sourceTree = "<group>"; };
104 108 DFF70C311039D8BC0052EE6A /* ImageContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImageContent.m; path = Classes/Samples/ImageContent.m; sourceTree = "<group>"; };
105 109 DFF70C451039D9E60052EE6A /* FTSLogo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FTSLogo.png; sourceTree = "<group>"; };
@@ -286,6 +290,8 @@
286 290 DFF7F659103634C70067ED5B /* KeyframeAnimation.m */,
287 291 DFF70D9C103A104C0052EE6A /* LayerActions.h */,
288 292 DFF70D9D103A104C0052EE6A /* LayerActions.m */,
  293 + DFAFBACD105EFF4200AE6FF1 /* LayerTransitions.h */,
  294 + DFAFBACE105EFF4200AE6FF1 /* LayerTransitions.m */,
289 295 );
290 296 name = Animation;
291 297 sourceTree = "<group>";
@@ -467,6 +473,7 @@
467 473 DFF70D9E103A104C0052EE6A /* LayerActions.m in Sources */,
468 474 DFF70DA2103A10870052EE6A /* AnimationTransactions.m in Sources */,
469 475 DFF70DC0103A11DF0052EE6A /* AnimationGroups.m in Sources */,
  476 + DFAFBACF105EFF4200AE6FF1 /* LayerTransitions.m in Sources */,
470 477 );
471 478 runOnlyForDeploymentPostprocessing = 0;
472 479 };
@@ -492,6 +499,7 @@
492 499 DFF70D9F103A104C0052EE6A /* LayerActions.m in Sources */,
493 500 DFF70DA3103A10870052EE6A /* AnimationTransactions.m in Sources */,
494 501 DFF70DC1103A11DF0052EE6A /* AnimationGroups.m in Sources */,
  502 + DFAFBAD0105EFF4200AE6FF1 /* LayerTransitions.m in Sources */,
495 503 );
496 504 runOnlyForDeploymentPostprocessing = 0;
497 505 };
2  Classes/Samples/ImageContent.m
@@ -43,6 +43,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
43 43 - (void)dealloc {
44 44 FTRELEASE(simpleLayer_);
45 45 FTRELEASE(moneyLayer_);
  46 + FTRELEASE(magicButton_);
46 47 [super dealloc];
47 48 }
48 49
@@ -70,6 +71,7 @@ - (void)loadView {
70 71 - (void)viewDidUnload {
71 72 FTRELEASE(simpleLayer_);
72 73 FTRELEASE(moneyLayer_);
  74 + FTRELEASE(magicButton_);
73 75 }
74 76
75 77 #pragma mark View drawing
38 Classes/Samples/LayerTransitions.h
... ... @@ -0,0 +1,38 @@
  1 +/*
  2 + The MIT License
  3 +
  4 + Copyright (c) 2009 Free Time Studios and Nathan Eror
  5 +
  6 + Permission is hereby granted, free of charge, to any person obtaining a copy
  7 + of this software and associated documentation files (the "Software"), to deal
  8 + in the Software without restriction, including without limitation the rights
  9 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10 + copies of the Software, and to permit persons to whom the Software is
  11 + furnished to do so, subject to the following conditions:
  12 +
  13 + The above copyright notice and this permission notice shall be included in
  14 + all copies or substantial portions of the Software.
  15 +
  16 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22 + THE SOFTWARE.
  23 +*/
  24 +
  25 +#import <UIKit/UIKit.h>
  26 +
  27 +
  28 +@interface LayerTransitions : UIViewController {
  29 + CALayer *containerLayer_;
  30 + CALayer *blueLayer_;
  31 + CALayer *redLayer_;
  32 +
  33 + UIButton *transitionButton_;
  34 + UISegmentedControl *typeSelectControl_;
  35 + UISegmentedControl *subtypeSelectControl_;
  36 +}
  37 +
  38 +@end
163 Classes/Samples/LayerTransitions.m
... ... @@ -0,0 +1,163 @@
  1 +/*
  2 + The MIT License
  3 +
  4 + Copyright (c) 2009 Free Time Studios and Nathan Eror
  5 +
  6 + Permission is hereby granted, free of charge, to any person obtaining a copy
  7 + of this software and associated documentation files (the "Software"), to deal
  8 + in the Software without restriction, including without limitation the rights
  9 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10 + copies of the Software, and to permit persons to whom the Software is
  11 + furnished to do so, subject to the following conditions:
  12 +
  13 + The above copyright notice and this permission notice shall be included in
  14 + all copies or substantial portions of the Software.
  15 +
  16 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22 + THE SOFTWARE.
  23 +*/
  24 +
  25 +#import "LayerTransitions.h"
  26 +#import <QuartzCore/QuartzCore.h>
  27 +
  28 +@implementation LayerTransitions
  29 +
  30 ++ (NSString *)friendlyName {
  31 + return @"Layer Transitions";
  32 +}
  33 +
  34 +#pragma mark init and dealloc
  35 +
  36 +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  37 + if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  38 + self.title = [[self class] friendlyName];
  39 + }
  40 + return self;
  41 +}
  42 +
  43 +- (void)dealloc {
  44 + FTRELEASE(containerLayer_);
  45 + FTRELEASE(blueLayer_);
  46 + FTRELEASE(redLayer_);
  47 + FTRELEASE(transitionButton_);
  48 + FTRELEASE(typeSelectControl_);
  49 + FTRELEASE(subtypeSelectControl_);
  50 + [super dealloc];
  51 +}
  52 +
  53 +#pragma mark Load and unload the view
  54 +
  55 +- (void)loadView {
  56 + UIView *myView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  57 + myView.backgroundColor = [UIColor grayColor];
  58 +
  59 + NSArray *typeItems = [NSArray arrayWithObjects:@"Push", @"Move In", @"Reveal", @"Fade", nil];
  60 + typeSelectControl_ = [[UISegmentedControl alloc] initWithItems:typeItems];
  61 + typeSelectControl_.frame = CGRectMake(10.f, 10.f, 300.f, 44.f);
  62 + typeSelectControl_.selectedSegmentIndex = 0;
  63 + [myView addSubview:typeSelectControl_];
  64 +
  65 + NSArray *subtypeItems = [NSArray arrayWithObjects:@"Right", @"Left", @"Top", @"Bottom", nil];
  66 + subtypeSelectControl_ = [[UISegmentedControl alloc] initWithItems:subtypeItems];
  67 + subtypeSelectControl_.frame = CGRectMake(10.f, 60.f, 300.f, 44.f);
  68 + subtypeSelectControl_.selectedSegmentIndex = 0;
  69 + [myView addSubview:subtypeSelectControl_];
  70 +
  71 + transitionButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
  72 + transitionButton_.frame = CGRectMake(10.f, 110.f, 300.f, 44.f);
  73 + [transitionButton_ setTitle:@"Start Transition" forState:UIControlStateNormal];
  74 + [transitionButton_ addTarget:self action:@selector(toggleTransition:) forControlEvents:UIControlEventTouchUpInside];
  75 + [myView addSubview:transitionButton_];
  76 +
  77 +
  78 + blueLayer_ = [[CALayer layer] retain];
  79 + redLayer_ = [[CALayer layer] retain];
  80 + containerLayer_ = [[CALayer layer] retain];
  81 +
  82 + [myView.layer addSublayer:containerLayer_];
  83 + [containerLayer_ addSublayer:blueLayer_];
  84 + [containerLayer_ addSublayer:redLayer_];
  85 + self.view = myView;
  86 +}
  87 +
  88 +- (void)viewDidUnload {
  89 + FTRELEASE(containerLayer_);
  90 + FTRELEASE(blueLayer_);
  91 + FTRELEASE(redLayer_);
  92 + FTRELEASE(transitionButton_);
  93 + FTRELEASE(typeSelectControl_);
  94 + FTRELEASE(subtypeSelectControl_);
  95 +}
  96 +
  97 +#pragma mark View drawing
  98 +
  99 +- (void)viewWillAppear:(BOOL)animated {
  100 + CGRect rect = CGRectMake(0.f, 0.f, 240.f, 240.f);
  101 +
  102 + containerLayer_.backgroundColor = [[UIColor clearColor] CGColor];
  103 + containerLayer_.bounds = rect;
  104 + containerLayer_.position = CGPointMake(160.f, 280.f);
  105 + [containerLayer_ setNeedsDisplay];
  106 +
  107 + redLayer_.backgroundColor = [UIColorFromRGBA(0xFF0000, .75f) CGColor];
  108 + redLayer_.bounds = rect;
  109 + redLayer_.position = CGPointMake(120.f, 120.f);
  110 + redLayer_.hidden = YES;
  111 + [redLayer_ setNeedsDisplay];
  112 +
  113 + blueLayer_.backgroundColor = [UIColorFromRGBA(0x0000FF, .75f) CGColor];
  114 + blueLayer_.bounds = rect;
  115 + blueLayer_.position = CGPointMake(120.f, 120.f);
  116 + [blueLayer_ setNeedsDisplay];
  117 +}
  118 +
  119 +//- (void)viewDidAppear:(BOOL)animated {
  120 +//
  121 +//}
  122 +
  123 +#pragma mark Button Event Handlers
  124 +
  125 +- (void)toggleTransition:(id)sender {
  126 + CATransition *transition = [CATransition animation];
  127 + transition.duration = .5f;
  128 + transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  129 + switch(typeSelectControl_.selectedSegmentIndex) {
  130 + case 0:
  131 + transition.type = kCATransitionPush;
  132 + break;
  133 + case 1:
  134 + transition.type = kCATransitionMoveIn;
  135 + break;
  136 + case 2:
  137 + transition.type = kCATransitionReveal;
  138 + break;
  139 + case 3:
  140 + transition.type = kCATransitionFade;
  141 + break;
  142 + }
  143 + switch(subtypeSelectControl_.selectedSegmentIndex) {
  144 + case 0:
  145 + transition.subtype = kCATransitionFromRight;
  146 + break;
  147 + case 1:
  148 + transition.subtype = kCATransitionFromLeft;
  149 + break;
  150 + case 2:
  151 + transition.subtype = kCATransitionFromTop;
  152 + break;
  153 + case 3:
  154 + transition.subtype = kCATransitionFromBottom;
  155 + break;
  156 + }
  157 +
  158 + [containerLayer_ addAnimation:transition forKey:nil];
  159 + blueLayer_.hidden = !blueLayer_.hidden;
  160 + redLayer_.hidden = !redLayer_.hidden;
  161 +}
  162 +
  163 +@end
4 Classes/Samples/SampleManager.m
@@ -37,6 +37,7 @@ of this software and associated documentation files (the "Software"), to deal
37 37 #import "LayerActions.h"
38 38 #import "AnimationTransactions.h"
39 39 #import "AnimationGroups.h"
  40 +#import "LayerTransitions.h"
40 41
41 42 @interface SampleManager ()
42 43
@@ -73,7 +74,8 @@ - (id)init {
73 74 NSArray *hier = [NSArray arrayWithObjects:[LayerTree class], nil];
74 75 NSArray *drawing = [NSArray arrayWithObjects:[ImageContent class], [LayerDrawing class], [StyleProperties class], nil];
75 76 NSArray *animation = [NSArray arrayWithObjects:[BasicAnimation class], [AnimationGroups class],
76   - [AnimationTransactions class], [KeyframeAnimation class], [LayerActions class], nil];
  77 + [AnimationTransactions class], [KeyframeAnimation class], [LayerActions class],
  78 + [LayerTransitions class], nil];
77 79 NSArray *special = [NSArray arrayWithObjects:[ShapeLayers class], [GradientLayers class], nil];
78 80
79 81

0 comments on commit 017137f

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