c4 - object notifications other than touches* don't work -


i trying attach notifications other touchesbegan c4shape , getting nothing. have added c4shape , have tried add other notifications @ bottom of setup. problem notification ever gets called touchesbegan.

i tried adding gestures la http://www.c4ios.com/examples/listenfor.php when touchesbegan notifications stop object.

#import "c4workspace.h"  @implementation c4workspace {     c4shape * topthing; }  -(void)setup {         c4font * f = [c4font fontwithname:@"arialroundedmtbold" size:50.0f];      topthing = [c4shape shapefromstring:@"touch me" withfont:f];     [topthing setcenter:cgpointmake(self.canvas.center.x, self.canvas.height/6)];     [self.canvas addsubview:topthing];     [topthing setanimationduration:2.0];      [self listenfor:@"touchesbegan" fromobject:topthing andrunmethod:@"bangg:"];     [self listenfor:@"tapped" fromobject:topthing andrunmethod:@"bangg:"];     [self listenfor:@"longpress" fromobject:topthing andrunmethod:@"bangg:"];     [self listenfor:@"swipedright" fromobject:topthing andrunmethod:@"bangg:"];      [self runmethod:@"fffff" afterdelay:1.0]; }  -(void) fffff {     [topthing  rect:cgrectmake(0, 0, self.canvas.width, self.canvas.height/3)];     [topthing setanimationduration:0.0]; }  - (void) bangg:(nsnotification *) notification {    c4log(@"%@", [notification name]); } @end 

two things happening here...

1) listening gesture broadcasts isn't enough. need add gestures shape broadcast. 3 gestures you're listening should use following code:

[topthing addgesture:tap name:@"tap" action:@"tapped:"]; [topthing addgesture:longpress name:@"long" action:@"pressedlong"]; [topthing addgesture:swiperight name:@"right" action:@"swipedright:"];  [self listenfor:@"tapped" fromobject:topthing andrunmethod:@"bang1:"]; [self listenfor:@"pressedlong" fromobject:topthing andrunmethod:@"bang2:"]; [self listenfor:@"swipedright" fromobject:topthing andrunmethod:@"bang3:"]; 

2) when add gestures shape expected behaviour turn off touchesbegan. reasoning in case add longpress gesture object expect method longpress gesture run after amount of time. if don't turn off touchesbegan both methods run: first touchesbegan gets triggered, longpress method gets triggered can troublesome if want long press method run. same logic applies gestures.

if want allow touchesbegan run can following:

[topthing gestureforname:@"tap"].delaystouchesbegan = no; [topthing gestureforname:@"long"].delaystouchesbegan = no; [topthing gestureforname:@"right"].delaystouchesbegan = no; 

...note has done gestures active on object.


if plan add complex gesture functionality objects, suggest subclassing , overriding individual methods -(void)tapped{} , -(void)swipedright{}. allow more customize actions rather dealing them canvas.


#import "c4workspace.h"  @implementation c4workspace { c4shape * topthing; }  -(void)setup {     c4font * f = [c4font fontwithname:@"arialroundedmtbold" size:50.0f];      topthing = [c4shape shapefromstring:@"touch me" withfont:f];     [topthing setcenter:cgpointmake(self.canvas.center.x, self.canvas.height/6)];     [self.canvas addsubview:topthing];     [topthing setanimationduration:2.0];      [topthing addgesture:tap name:@"tap" action:@"tapped:"];     [topthing addgesture:longpress name:@"long" action:@"pressedlong"];     [topthing addgesture:swiperight name:@"right" action:@"swipedright:"];      [self listenfor:@"tapped:" fromobject:topthing andrunmethod:@"bang1:"];     [self listenfor:@"pressedlong" fromobject:topthing andrunmethod:@"bang2:"];     [self listenfor:@"swipedright" fromobject:topthing andrunmethod:@"bang3:"];      [self runmethod:@"fffff" afterdelay:1.0]; }  -(void) fffff {     [topthing  rect:cgrectmake(0, 0, self.canvas.width, self.canvas.height/3)];     [topthing setanimationduration:0.0]; }  -(void)bang1:(nsnotification *)notification {c4log(@"%@",[notification name]);} -(void)bang2:(nsnotification *)notification {c4log(@"%@",[notification name]);} -(void)bang3:(nsnotification *)notification {c4log(@"%@",[notification name]);} @end 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -