Is the Pinch gesture supported in C4?

110 Views Asked by At

I just downloaded C4 and am trying to get the pinch gesture going in some sample code where I already have the swipe gesture going. The code is as follows:

[ball addGesture:SWIPERIGHT name:@"swipeR" action:@"swipeBall"];
[ball addGesture:PINCH name:@"pinch" action:@"zoomBall"];

as soon as I add the second line with the PINCH i get the following error message on compile which seems weird given PINCH is listed in the list mentioned in the error message below. Any ideas what's up?

Error Message:

2012-10-10 00:58:06.166 Test[24121:10703] *** Assertion failure in -[MyBall addGesture:name:action:], /Users/moi/Development/C4Installer/libC4/libC4/C4Control.m:319

2012-10-10 00:58:06.184 Test[24121:10703] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The gesture you tried to use is not one of: TAP, PINCH, SWIPERIGHT, SWIPELEFT, SWIPEUP, SWIPEDOWN, ROTATION, PAN, or LONGPRESS'

*** First throw call stack: (0x320022 0x1730cd6 0x2c8a48 0x99c2cb 0xcdd3 0x380b 0x3190 0xe2b386 0xe2c274 0xe3b183 0xe3bc38 0xe2f634 0x3c2eef5 0x2f4195 0x258ff2 0x2578da 0x256d84 0x256c9b 0xe2bc65 0xe2d626 0x2d3d 0x2ca5) terminate called throwing an exception(lldb)

2

There are 2 best solutions below

0
On

Unfortunately, I haven't implemented the PINCH gesture yet. The variable is available, just as a placeholder. I will hopefully get it into the API soon.

0
On

I think I managed to implement this.

I went into c4CanvasController and added this to the addGesture method:

case PINCH:
            recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:NSSelectorFromString(methodName)];
            break;

Then I added the gesture to the project as usual:

[self addGesture:PINCH name:@"pinchme" action:@"customPinchMethod:"];

I defined a pinch and zoom like behaviour for the pinch gestures callback method.

    -(void)customPinchMethod:(UIPinchGestureRecognizer*)sender {
    NSLog(@"Pinching");

    NSLog(@"latscale = %f",mLastScale);

    mScale = sender.scale*mLastScale;
    if (sender.state == UIGestureRecognizerStateEnded) mLastScale = mScale;

    CGAffineTransform currentTransform = CGAffineTransformIdentity;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, mScale ,mScale);
    self.view.transform = newTransform; 

}