Created
January 24, 2013 20:48
-
-
Save C4Code/4627567 to your computer and use it in GitHub Desktop.
Example of tying the movement of two objects together with Listeners and Gestures
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 | |
// | |
// Created by Travis Kirton | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *s1, *s2; | |
} | |
-(void)setup { | |
s1 = [C4Shape ellipse:CGRectMake(0, 0, 44, 44)]; | |
s2 = [C4Shape ellipse:s1.frame]; | |
[self.canvas addShape:s2]; | |
[self.canvas addShape:s1]; | |
[s1 addGesture:PAN name:@"pan" action:@"move:"]; | |
[self listenFor:@"moved" fromObject:s1 andRunMethod:@"moveS2"]; | |
[s2 addGesture:PAN name:@"pan" action:@"move:"]; | |
[self listenFor:@"moved" fromObject:s2 andRunMethod:@"moveS1"]; | |
} | |
-(void)moveS1 { | |
CGPoint p = s2.center; | |
p.x = s1.center.x; | |
s1.center = p; | |
} | |
-(void)moveS2 { | |
CGPoint p = s1.center; | |
p.x = s2.center.x; | |
s2.center = p; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment