Skip to content

Commit

Permalink
Converting to ARC.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmccune committed Feb 29, 2012
1 parent 503d5f5 commit a66f681
Show file tree
Hide file tree
Showing 36 changed files with 152 additions and 194 deletions.
8 changes: 3 additions & 5 deletions Classes/CoreAnimation/AVPlayerLayerViewController.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,10 +27,8 @@
/*
* Demo of moving AVPlayerLayer around in 3D space.
*/
@interface AVPlayerLayerViewController : UIViewController {
AVPlayer *player;
}
@interface AVPlayerLayerViewController : UIViewController

@property (nonatomic, retain) AVPlayer *player;
@property (nonatomic, strong) AVPlayer *player;

@end
8 changes: 3 additions & 5 deletions Classes/CoreAnimation/AVPlayerLayerViewController.m
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,6 +27,8 @@

@implementation AVPlayerLayerViewController

@synthesize player = _player;

+ (NSString *)displayName {
return @"Amazon Babe";
}
Expand Down Expand Up @@ -91,10 +93,6 @@ - (void)spinIt {

- (void)dealloc {
[self.player pause];
self.player = nil;
[super dealloc];
}

@synthesize player;

@end
6 changes: 2 additions & 4 deletions Classes/CoreAnimation/BatmanViewController.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,9 +25,7 @@
/*
* Demo showing how to animate transforms and combine multiple animations into a CAAnimationGroup.
*/
@interface BatmanViewController : UIViewController {
CALayer *logoLayer;
}
@interface BatmanViewController : UIViewController

- (IBAction)rotate:(id)sender;
- (IBAction)scaleUp;
Expand Down
30 changes: 18 additions & 12 deletions Classes/CoreAnimation/BatmanViewController.m
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,8 +27,14 @@
#define ROTATE_LEFT_TAG 3
#define ROTATE_RIGHT_TAG 4

@interface BatmanViewController ()
@property (nonatomic, strong) CALayer *logoLayer;
@end

@implementation BatmanViewController

@synthesize logoLayer = _logoLayer;

- (id)init {
self = [super initWithNibName:@"BatmanView" bundle:nil];
return self;
Expand All @@ -46,13 +52,13 @@ - (void)viewDidLoad {

UIImage *image = [UIImage imageNamed:@"batman.png"];

logoLayer = [CALayer layer];
logoLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
logoLayer.position = CGPointMake(160, 180);
logoLayer.contents = (id)image.CGImage;
self.logoLayer = [CALayer layer];
self.logoLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
self.logoLayer.position = CGPointMake(160, 180);
self.logoLayer.contents = (id)image.CGImage;

// Add layer as a sublayer of the UIView's layer
[self.view.layer addSublayer:logoLayer];
[self.view.layer addSublayer:self.logoLayer];
}

- (IBAction)rotate:(id)sender {
Expand All @@ -61,7 +67,7 @@ - (IBAction)rotate:(id)sender {
rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * direction];
rotationAnimation.duration = 1.0f;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[logoLayer addAnimation:rotationAnimation forKey:@"rotateAnimation"];
[self.logoLayer addAnimation:rotationAnimation forKey:@"rotateAnimation"];
}

- (void)scaleByFactor:(CGFloat)factor {
Expand All @@ -71,17 +77,17 @@ - (void)scaleByFactor:(CGFloat)factor {
scaleAnimation.duration = 3.0f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// Set the model layer's property so the animation sticks at the 'toValue' state
[logoLayer setValue:scaleFactor forKeyPath:@"transform.scale"];
[logoLayer addAnimation:scaleAnimation forKey:@"transformAnimation"];
[self.logoLayer setValue:scaleFactor forKeyPath:@"transform.scale"];
[self.logoLayer addAnimation:scaleAnimation forKey:@"transformAnimation"];
}

- (IBAction)scaleDown {
CGFloat factor = [[logoLayer valueForKeyPath:@"transform.scale"] floatValue] > 1.0 ? 1.0 : 0.5;
CGFloat factor = [[self.logoLayer valueForKeyPath:@"transform.scale"] floatValue] > 1.0 ? 1.0 : 0.5;
[self scaleByFactor:factor];
}

- (IBAction)scaleUp {
CGFloat factor = [[logoLayer valueForKeyPath:@"transform.scale"] floatValue] == 0.5 ? 1.0 : 1.5;
CGFloat factor = [[self.logoLayer valueForKeyPath:@"transform.scale"] floatValue] == 0.5 ? 1.0 : 1.5;
[self scaleByFactor:factor];
}

Expand All @@ -106,7 +112,7 @@ - (IBAction)doBatmanAnimation {
animationGroup.repeatCount = HUGE_VALF;
[animationGroup setAnimations:[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil]];

[logoLayer addAnimation:animationGroup forKey:@"animationGroup"];
[self.logoLayer addAnimation:animationGroup forKey:@"animationGroup"];
}

@end
4 changes: 1 addition & 3 deletions Classes/CoreAnimation/CALayer+Additions.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,8 +21,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Foundation/Foundation.h>


@interface CALayer (Additions)

Expand Down
3 changes: 1 addition & 2 deletions Classes/CoreAnimation/CALayer+Additions.m
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,6 @@

#import "CALayer+Additions.h"


@implementation CALayer (Additions)

- (void)adjustWidthBy:(CGFloat)value {
Expand Down
6 changes: 2 additions & 4 deletions Classes/CoreAnimation/CharlieViewController.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,8 +25,6 @@
/*
* Demo using shadowPath property to give greater depth and realism to layers. Tap photo to toggle shadow path.
*/
@interface CharlieViewController : UIViewController {

}
@interface CharlieViewController : UIViewController

@end
3 changes: 1 addition & 2 deletions Classes/CoreAnimation/CharlieViewController.m
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -76,7 +76,6 @@ - (void)viewDidLoad {

UIGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePath)];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}

- (void)togglePath {
Expand Down
9 changes: 3 additions & 6 deletions Classes/CoreAnimation/ImplicitAnimationsViewController.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,12 +25,9 @@
/*
* Simple demo showing implicit property animations.
*/
@interface ImplicitAnimationsViewController : UIViewController {
CALayer *layer;
UISwitch *actionsSwitch;
}
@interface ImplicitAnimationsViewController : UIViewController

@property (nonatomic, retain) IBOutlet UISwitch *actionsSwitch;
@property (nonatomic, strong) IBOutlet UISwitch *actionsSwitch;

- (IBAction)toggleCornerRadius;
- (IBAction)toggleBorder;
Expand Down
49 changes: 27 additions & 22 deletions Classes/CoreAnimation/ImplicitAnimationsViewController.m
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -29,21 +29,28 @@
#define ORGINAL_POSITION CGPointMake(160, 250)
#define MOVED_POSITON CGPointMake(200, 290)

@interface ImplicitAnimationsViewController ()
@property (nonatomic, strong) CALayer *layer;
@end

@implementation ImplicitAnimationsViewController

@synthesize actionsSwitch = _actionsSwitch;
@synthesize layer = _layer;

+ (NSString *)displayName {
return @"Animatable Properties";
}

- (id)init {
if ((self = [super initWithNibName:@"LayerView" bundle:nil])) {
layer = [CALayer layer];
layer.bounds = CGRectMake(0, 0, 200, 200);
layer.position = CGPointMake(160, 250);
layer.backgroundColor = [UIColor redColor].CGColor;
layer.borderColor = [UIColor blackColor].CGColor;
layer.opacity = 1.0f;
[self.view.layer addSublayer:layer];
self.layer = [CALayer layer];
self.layer.bounds = CGRectMake(0, 0, 200, 200);
self.layer.position = CGPointMake(160, 250);
self.layer.backgroundColor = [UIColor redColor].CGColor;
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.opacity = 1.0f;
[self.view.layer addSublayer:self.layer];
}
return self;
}
Expand All @@ -55,36 +62,34 @@ - (void)viewDidLoad {
}

- (IBAction)toggleColor {
[CATransaction setDisableActions:actionsSwitch.on];
[CATransaction setDisableActions:self.actionsSwitch.on];
CGColorRef redColor = [UIColor redColor].CGColor, blueColor = [UIColor blueColor].CGColor;
layer.backgroundColor = (layer.backgroundColor == redColor) ? blueColor : redColor;
self.layer.backgroundColor = (self.layer.backgroundColor == redColor) ? blueColor : redColor;
}

- (IBAction)toggleCornerRadius {
[CATransaction setDisableActions:actionsSwitch.on];
layer.cornerRadius = (layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
[CATransaction setDisableActions:self.actionsSwitch.on];
self.layer.cornerRadius = (self.layer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
}

- (IBAction)toggleBorder {
[CATransaction setDisableActions:actionsSwitch.on];
layer.borderWidth = (layer.borderWidth == 0.0f) ? 10.0f : 0.0f;
[CATransaction setDisableActions:self.actionsSwitch.on];
self.layer.borderWidth = (self.layer.borderWidth == 0.0f) ? 10.0f : 0.0f;
}

- (IBAction)toggleOpacity {
[CATransaction setDisableActions:actionsSwitch.on];
layer.opacity = (layer.opacity == 1.0f) ? 0.5f : 1.0f;
[CATransaction setDisableActions:self.actionsSwitch.on];
self.layer.opacity = (self.layer.opacity == 1.0f) ? 0.5f : 1.0f;
}

- (IBAction)toggleBounds {
[CATransaction setDisableActions:actionsSwitch.on];
[layer adjustWidthBy:layer.bounds.size.width == layer.bounds.size.height ? 100 : -100];
[CATransaction setDisableActions:self.actionsSwitch.on];
[self.layer adjustWidthBy:self.layer.bounds.size.width == self.layer.bounds.size.height ? 100 : -100];
}

- (IBAction)togglePosition {
[CATransaction setDisableActions:actionsSwitch.on];
layer.position = layer.position.x == 160 ? MOVED_POSITON : ORGINAL_POSITION;
[CATransaction setDisableActions:self.actionsSwitch.on];
self.layer.position = self.layer.position.x == 160 ? MOVED_POSITON : ORGINAL_POSITION;
}

@synthesize actionsSwitch;

@end
6 changes: 2 additions & 4 deletions Classes/CoreAnimation/MakeItStickViewController.h
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2011 Bob McCune http://bobmccune.com/
// Copyright (c) 2012 Bob McCune http://bobmccune.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,8 +26,6 @@
* Demo pointing out a gotcha when applying animations. Need to update the model value to ensure
* the animation's 'toValue' sticks.
*/
@interface MakeItStickViewController : UIViewController {
CALayer *layer;
}
@interface MakeItStickViewController : UIViewController

@end

0 comments on commit a66f681

Please sign in to comment.