0

I am trying to do zoom-in and zoom-out in a UIView using UIPinchGestureRecognizer. But when I do pinch on my trackpad, it is not recognising the pinch and the control is not going to my twoFingerPinch function. I am using the following code.

- (void)viewDidLoad {
//.......
UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc]
                      initWithTarget:self
                      action:@selector(twoFingerPinch:)];
    [myview addGestureRecognizer:twoFingerPinch];
//.....
}

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
    NSLog(@"Pinch scale: %f", recognizer.scale);
    if (recognizer.scale >1.0f && recognizer.scale < 2.5f) {
        CGAffineTransform transform = CGAffineTransformMakeScale(recognizer.scale, recognizer.scale//);
        myview.transform = transform;
    }
}

Why it is not recognising the pinch from trackpad? Is there any other method to do the same?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
itzmebibin
  • 9,199
  • 8
  • 48
  • 62

2 Answers2

1

First click on the Option button. you will get 2 gray spots which you can move using the mouse or trackpad. in older versions you need to press shift+option.

for more details check this.

Community
  • 1
  • 1
Raul
  • 11
  • 8
  • Got it. Thanks. It was not the error in my code. I was not knowing about the use of Option button to do pinching. – itzmebibin Aug 08 '16 at 13:59
1

Make sure that userInteractionEnabled is set to yes for your myview,

 myview.userInteractionEnabled = YES;
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75