I’m just learning how to use the C4 framework and trying to add gestures to a shape, but I can’t seem to figure out how to get them to do anything. The following method creates an error, when I try to change the position of a button after it is tapped.
[buttonA addGesture:TAP name:@"tapGesture" action:@"setPosition"];
This is the error I get: * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[MyButton setPosition]: unrecognized selector sent to instance 0x7661b60’
I’m guessing that the reason you’re getting the error is because the setPosition method is because you’re trying to run the
setPositionmethod directly on a C4Shape object. Natively, C4Shapes don’t have this method.In C4, all objects can have gestures attached to them, but in order run any custom code when you trigger a gesture on an object you should first subclass C4Shape and write a special method to handle the behaviour you want to see.
For example, I would create a MyShape class like this:
Then, in my C4WorkSpace:
This should register a tap gesture with your new subclassed shape, and run its
setNewPositionmethod when the gesture is triggered.