Skip to content

Commit

Permalink
* Removed FTUtils so the samples can stand alone
Browse files Browse the repository at this point in the history
* Added ShutterTransition example
* Added AdvancedShapeLayer example
* Added some Xcode 4 specific stuff to .gitignore
  • Loading branch information
neror committed Aug 31, 2010
1 parent 16c046c commit 924d98b
Show file tree
Hide file tree
Showing 30 changed files with 544 additions and 256 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,5 @@ build
*.mode1v3
*.pbxuser
*.perspectivev3
CA360.xcodeproj/project.xcworkspace
CA360.xcodeproj/xcuserdata
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

168 changes: 47 additions & 121 deletions CA360.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CA360_Prefix.pch
Expand Up @@ -31,5 +31,5 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "FTUtils/FTUtils.h"
#import "UsefulMacros.h"
#endif
6 changes: 3 additions & 3 deletions Classes/CA360AppDelegate.m
Expand Up @@ -48,9 +48,9 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
#pragma mark Memory management

- (void)dealloc {
FTRELEASE(rootViewController_);
FTRELEASE(navigationController_);
FTRELEASE(window_);
[rootViewController_ release], rootViewController_ = nil;
[navigationController_ release], navigationController_ = nil;
[window_ release], window_ = nil;
[super dealloc];
}

Expand Down
18 changes: 10 additions & 8 deletions Classes/Fun Stuff/BitmapFontCounter.m
Expand Up @@ -8,8 +8,6 @@

@implementation CounterView

@synthesize number = number_;

- (CounterView *)initWithNumber:(double)num {
if (self = [super initWithFrame:CGRectMake(0.f, 0.f, kDigitWidth, kDigitHeight)]) {
digitLayers_ = [[NSMutableArray alloc] init];
Expand All @@ -19,15 +17,19 @@ - (CounterView *)initWithNumber:(double)num {
}

- (void)dealloc {
FTRELEASE(numberString_);
FTRELEASE(digitLayers_);
[numberString_ release], numberString_ = nil;
[digitLayers_ release], digitLayers_ = nil;
[super dealloc];
}

- (double)number {
return number_;
}

- (void)setNumber:(double)num {
number_ = num;
[digitLayers_ makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
FTRELEASE(numberString_);
[numberString_ release], numberString_ = nil;
numberString_ = [[NSString stringWithFormat:@"%.0F", num] retain];

NSUInteger count = [numberString_ length];
Expand Down Expand Up @@ -99,9 +101,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
}

- (void)dealloc {
FTRELEASE(counter_);
FTRELEASE(textField_);
FTRELEASE(setNumberButton_);
[counter_ release], counter_ = nil;
[textField_ release], textField_ = nil;
[setNumberButton_ release], setNumberButton_ = nil;
[super dealloc];
}

Expand Down
33 changes: 33 additions & 0 deletions Classes/Fun Stuff/ShutterTransition.h
@@ -0,0 +1,33 @@
/*
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>
#import <QuartzCore/QuartzCore.h>

@interface ShutterTransition : UIViewController {
CALayer *mainLayer_;
UIButton *goButton_;
}

@end
173 changes: 173 additions & 0 deletions Classes/Fun Stuff/ShutterTransition.m
@@ -0,0 +1,173 @@
/*
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 "ShutterTransition.h"

#define USE_FLATTENED_LAYER 0
#define BAND_COUNT 7

@implementation ShutterTransition

+ (NSString *)friendlyName {
return @"Shutter Transition";
}

#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 {
[goButton_ release], goButton_ = nil;
[mainLayer_ release], mainLayer_ = nil;
[super dealloc];
}

#pragma mark Load and unload the view

- (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];

mainLayer_ = [[CALayer alloc] init];

[self.view.layer addSublayer:mainLayer_];

goButton_ = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
goButton_.frame = CGRectMake(10., 10., 300., 44.);
[goButton_ setTitle:@"Shutter Transition!" forState:UIControlStateNormal];
[goButton_ addTarget:self action:@selector(doShutterTransition) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:goButton_];

}

- (void)viewDidUnload {
[mainLayer_ release], mainLayer_ = nil;
[goButton_ release], goButton_ = nil;
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
CGContextAddEllipseInRect(ctx, mainLayer_.bounds);
CGContextSetStrokeColorWithColor(ctx, [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(ctx, 4.f);
CGContextDrawPath(ctx, kCGPathStroke);
}

#pragma mark View drawing

- (void)viewWillAppear:(BOOL)animated {
mainLayer_.delegate = self;
mainLayer_.bounds = CGRectMake(0.f, 0.f, 200.f, 200.f);
mainLayer_.backgroundColor = [[UIColor blueColor] CGColor];
mainLayer_.position = self.view.center;
[mainLayer_ setNeedsDisplay];
}

- (void)viewWillDisappear:(BOOL)animated {
mainLayer_.delegate = nil;
}

#pragma mark -
#pragma mark Event Handlers

- (void)doShutterTransition {
CGSize layerSize = mainLayer_.bounds.size;

#if USE_FLATTENED_LAYER
//Grab the bits from the layer
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, (int)layerSize.width, (int)layerSize.height, 8, (int)layerSize.width * 4, colorSpace, kCGImageAlphaPremultipliedLast);

[mainLayer_ renderInContext:context];
UIImage *layerImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];
#endif

//Set up a single instance of the slide animations to be reused in the bands
CABasicAnimation *slideUp = [CABasicAnimation animationWithKeyPath:@"position.y"];
slideUp.toValue = [NSNumber numberWithFloat:-(mainLayer_.frame.size.height / 2.f)];
slideUp.duration = 1.f;
slideUp.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slideUp.fillMode = kCAFillModeForwards;

CABasicAnimation *slideDown = [CABasicAnimation animationWithKeyPath:@"position.y"];
slideDown.toValue = [NSNumber numberWithFloat:(mainLayer_.frame.size.height / 2.f) + [UIScreen mainScreen].bounds.size.height];
slideDown.duration = 1.f;
slideDown.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slideDown.fillMode = kCAFillModeForwards;

NSMutableArray *bands = [[NSMutableArray alloc] initWithCapacity:BAND_COUNT];

[mainLayer_ removeFromSuperlayer];
[CATransaction begin];
[CATransaction setCompletionBlock:^(void) {
[bands enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj setDelegate:nil];
[obj removeFromSuperlayer];
}];
[self.view.layer addSublayer:mainLayer_];
}];

CGFloat bandWidth = layerSize.width / (CGFloat)BAND_COUNT;
for(int i = 0; i < BAND_COUNT; i++) {
CALayer *band = [[CALayer alloc] init];
band.masksToBounds = YES;

#if USE_FLATTENED_LAYER
CGFloat xOffset = 1.f / (CGFloat)BAND_COUNT;
band.bounds = CGRectMake(0.f, 0.f, bandWidth, layerSize.height);
band.contents = (id)[layerImage CGImage];
band.contentsGravity = kCAGravityCenter;
band.contentsRect = CGRectMake(xOffset * i , 0.f, xOffset, 1.f);
#else
band.bounds = CGRectMake(bandWidth * i, 0.f, bandWidth, layerSize.height);
band.backgroundColor = mainLayer_.backgroundColor;
band.delegate = self;
[band setNeedsDisplay];
#endif

CGPoint bandOrigin = mainLayer_.frame.origin;
bandOrigin.x = bandOrigin.x + (bandWidth * i);
[band setValue:[NSValue valueWithCGPoint:bandOrigin] forKeyPath:@"frame.origin"];

[self.view.layer addSublayer:band];

[band addAnimation:(i % 2) ? slideUp : slideDown forKey:nil];
[bands addObject:band];
[band release];
}
[CATransaction commit];

[bands release];

#if USE_FLATTENED_LAYER
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
#endif
}


@end
3 changes: 3 additions & 0 deletions Classes/RootViewController.h
Expand Up @@ -22,7 +22,10 @@
THE SOFTWARE.
*/

@class SampleManager;

@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
SampleManager *sampleManager_;
}

@end
32 changes: 18 additions & 14 deletions Classes/RootViewController.m
Expand Up @@ -27,44 +27,48 @@ of this software and associated documentation files (the "Software"), to deal

@implementation RootViewController

- (void)dealloc {
[sampleManager_ release], sampleManager_ = nil;
[super dealloc];
}

- (void)viewDidLoad {
sampleManager_ = [[SampleManager alloc] init];
self.title = @"Samples";
}

- (void)viewDidUnload {
[sampleManager_ release], sampleManager_ = nil;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [SampleManager groupCount];
return [sampleManager_ groupCount];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [SampleManager sampleCountForGroup:section];
return [sampleManager_ sampleCountForGroup:section];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [SampleManager groupTitleAtIndex:section];
return [sampleManager_ groupTitleAtIndex:section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *title = [SampleManager sampleNameAtIndexPath:indexPath];
NSString *theTitle = [sampleManager_ sampleNameAtIndexPath:indexPath];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:title];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:theTitle];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:title] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:theTitle] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = title;
cell.textLabel.text = theTitle;
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *controller = [SampleManager sampleInstanceAtIndexPath:indexPath];
[self.navigationController pushViewController:controller animated:YES];
[self.navigationController pushViewController:[sampleManager_ sampleForIndexPath:indexPath] animated:YES];
}

- (void)dealloc {
[super dealloc];
}


@end

33 changes: 33 additions & 0 deletions Classes/Samples/AdvancedShapeLayers.h
@@ -0,0 +1,33 @@
/*
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>
#import <QuartzCore/QuartzCore.h>

@interface AdvancedShapeLayers : UIViewController {
CAShapeLayer *shapeLayer_;
CGFloat currentArc;
}

@end

0 comments on commit 924d98b

Please sign in to comment.