Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinch & Rotate: UIGestureRecognizerDelegate not called

I'm trying to implement both a pinch and a rotate in the same view. Sometimes the pinch selector gets called and sometimes the rotation one, ok, but then it sticks with it. The problem is clearly that gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer isn't being called. Why not? Got to be something obvious...

@interface FaceView : UIView <UIGestureRecognizerDelegate>
{
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end

@implementation FaceView
- (id)initWithFrame:(CGRect)frame
{
    if( self = [super initWithFrame:frame] )
    {
        self.multipleTouchEnabled = YES;
        self.userInteractionEnabled = YES;

        UIRotationGestureRecognizer* rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
        [self addGestureRecognizer:rotationRecognizer];
        [rotationRecognizer release];

        UIPinchGestureRecognizer* pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
        [self addGestureRecognizer:pinchRecognizer];
        [pinchRecognizer release];
    }
    return self;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    NSLog(@"gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer");
    return YES;
}

- (void)rotationGesture:(UIRotationGestureRecognizer*)gesture
{
    switch( gesture.state )
    {
        case UIGestureRecognizerStateBegan:
            NSLog(@"rotationGesture began");
            break;

        case UIGestureRecognizerStateChanged:
            NSLog(@"rotationGesture changed");
            break;
    }
}

- (void)pinchGesture:(UIPinchGestureRecognizer*)gesture
{
    switch( gesture.state )
    {
        case UIGestureRecognizerStateBegan:
            NSLog(@"pinchGesture began");
            break;

        case UIGestureRecognizerStateChanged:
            NSLog(@"pinchGesture changed");
            break;
    }
}
....
like image 505
Steve Rogers Avatar asked Dec 04 '22 19:12

Steve Rogers


1 Answers

I had to set rotationRecognizer.delegate = self; and pinchRecognizer.delegate = self;

like image 174
Steve Rogers Avatar answered Jan 04 '23 06:01

Steve Rogers