What I'm hoping to achieve is to call a method in C4Workspace.m by using:
[shape addGesture:SWIPELEFT name:@"swipeLeft" action:@"leftSwipeMethod"];
I know that this attempts to call a method called "leftSwipeMethod" within the C4Shape class, but in the documentation it also mentions you can call methods from the super class (which is what I think I'm trying to do?).
I checked other questions like this and I'm aware that you're not supposed to do this in normal objective-c... but I wonder if that is the case with C4 as well.
Is there any other way to get the same result or do I have to create a sub class?
Okay, the easiest way to do this is to set up your canvas to listen for the right method that is being called inside the C4Shape (actually, it's from any C4Control so this technique will work for all visual objects.
swipe
methodnotification
from the shapeThe following code sets up the shape:
However, this is hard-coded... A nicer, more dynamic way of doing this is to listen from a lot of objects and have a
randomColor:
method that also accepts the notification so that you can pull out the shape that's doing the notifying.Things to note in the second example:
First, to accept a notification, the method being run has to have the format:
Second, to trigger this the method name you use in
listenFor
has to have a:
like so:Third, you grab the object that just received a swipe gesture by pulling it from the notification it sent: