Created
May 3, 2013 16:32
-
-
Save C4Code/5510766 to your computer and use it in GitHub Desktop.
Button Subclass with Canvas Listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MyShape.h | |
// button subclass with canvas listener | |
// | |
#import "C4Shape.h" | |
@interface MyShape : C4Shape | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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