Skip to content

Instantly share code, notes, and snippets.

@C4Tutorials
Created April 8, 2013 20:28
Show Gist options
  • Save C4Tutorials/5340194 to your computer and use it in GitHub Desktop.
Save C4Tutorials/5340194 to your computer and use it in GitHub Desktop.
Grabbing an object from a notification.
//
// C4WorkSpace.m
// Notification Tutorial
//
// Created by Travis Kirton.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace
-(void)setup {
C4Shape *s1 = [C4Shape ellipse:CGRectMake(0, 0, 192, 192)];
C4Shape *s2 = [C4Shape ellipse:s1.frame];
C4Shape *s3 = [C4Shape ellipse:s1.frame];
s1.center = CGPointMake(self.canvas.center.x, self.canvas.height * 0.25f);
s2.center = self.canvas.center;
s3.center = CGPointMake(self.canvas.center.x, self.canvas.height * 0.75f);
[self.canvas addObjects:@[s1,s2,s3]];
[self listenFor:@"touchesBegan" fromObjects:@[s1,s2,s3] andRunMethod:@"randomColor:"];
}
-(void)randomColor:(NSNotification *)notification {
C4Shape *shape = (C4Shape *)notification.object;
shape.fillColor = [UIColor colorWithRed:[C4Math randomInt:100]/100.0f
green:[C4Math randomInt:100]/100.0f
blue:[C4Math randomInt:100]/100.0f
alpha:1.0f];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment