I'm trying to add an action once an image was tapped. I first tried adding a C4Button and then giving it an image but that didn't work out at all. So now I'm trying to just add a tap function to an image here is the code
-(void)setup{
//IMAGE AS BUTTON
C4Image *photoButtonImage=[C4Image imageNamed:@"icons-02.png"];
photoButtonImage.height=NavBarHeight;
photoButtonImage.center=CGPointMake(self.canvas.width/2, self.canvas.height-NavBarHeight/2);
[self.canvas addImage:photoButtonImage];
[photoButtonImage addGesture:TAP name:@"tap" action:@"tapped"];
}
-(void)tapped {
C4Log(@"tapped!");
}
applying the [photoButtonImage addGesture:TAP name:@"tap" action:@"tapped"];
method to self
totally works fine but nothing happens if I add it to the image (PhotoButtonImage
).
I've looked into 2 answers (Gesture controls crash when calling methods on C4WorkSpace.m and How do I apply a UILongPressGestureRecognizer to a shape in C4?). They are for shapes and I thought it should just work the same for images, but apparently it doesn't...
Adam's answer is correct for gestures. Generally, you want to use them when you want some extra / custom functionality for objects.
However, in your case you want to simply use the image as a button, you can do the following to achieve that without having to use a gesture:
[self listenFor:@"touchesBegan" fromObject:photoImage andRunMethod:@"aMethod"];
The reason for this is that all C4 objects will post basic touch notifications by default.