Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created May 3, 2013 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C4Code/5510766 to your computer and use it in GitHub Desktop.
Save C4Code/5510766 to your computer and use it in GitHub Desktop.
Button Subclass with Canvas Listener
//
// C4WorkSpace.m
// button subclass with canvas listener
//
#import "C4WorkSpace.h"
#import "MyShape.h"
@implementation C4WorkSpace
-(void)setup {
MyShape *m = [[MyShape alloc] init];
[m rect:CGRectMake(0, 0, 100, 100)];
m.center = self.canvas.center;
[self.canvas addShape:m];
[self listenFor:@"tapNotification" fromObject:m andRunMethod:@"heardTap:"];
}
-(void)heardTap:(NSNotification *)aNotification {
MyShape *notificationShape = (MyShape *)[aNotification object];
C4Log(@"%4.2f,%4.2f",notificationShape.center.x,notificationShape.center.y);
C4Log(@"%@",notificationShape.strokeColor);
}
@end
//
// MyShape.h
// button subclass with canvas listener
//
#import "C4Shape.h"
@interface MyShape : C4Shape
@end
//
// MyShape.m
// button subclass with canvas listener
//
#import "MyShape.h"
@implementation MyShape
-(void)setup {
[self addGesture:TAP name:@"tap" action:@"tapped"];
}
-(void)tapped {
[self postNotification:@"tapNotification"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment