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;
}
}
....
I had to set rotationRecognizer.delegate = self;
and pinchRecognizer.delegate = self;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With