1

I am working on the pdf based application where I am trying to implement UIPinchGestureRecognizer.I want to limit the pinch off functionality when user reaches to the default view size with 640,960.

In my current implementation user is able to pinch in/out infinite.

- (void)pinchZoom:(UIPinchGestureRecognizer *)gestureRecognizer
{
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        if (!zoomActive) {
            zoomActive = YES;

            UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panMove:)];
            [panGesture setMaximumNumberOfTouches:2];
            [panGesture setDelegate:self];
            [self addGestureRecognizer:panGesture];
            [panGesture release];

        }

        [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);

        [delegate leavesView:self zoomingCurrentView:[gestureRecognizer scale]];            

        [gestureRecognizer setScale:1];


    }
}  

    // This method will handle the PAN / MOVE gesture 
- (void)panMove:(UIPanGestureRecognizer *)gestureRecognizer    
{
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {  
        CGPoint translation = [gestureRecognizer translationInView:[[gestureRecognizer view] superview]];  
        [[gestureRecognizer view] setCenter:CGPointMake([[gestureRecognizer view] center].x + translation.x, [[gestureRecognizer view] center].y + translation.y)];  
        [gestureRecognizer setTranslation:CGPointZero inView:[[gestureRecognizer view] superview]];   
    }  
}

this is default view size/scale I am talking about:default pdf

and this is what I don't want or I want to limit in pinch out:
infinite pinch out

Any suggestion?

j0k
  • 22,600
  • 28
  • 79
  • 90
maddy
  • 4,001
  • 8
  • 42
  • 65

2 Answers2

3

What about handling yourself the lower limit in your handler function? Something like this:

- (void)pinchZoom:(UIPinchGestureRecognizer *)gestureRecognizer {

     ....

    if ( [gestureRecognizer scale] > MIN_SCALE )
        [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
  ...
sergio
  • 68,819
  • 11
  • 102
  • 123
  • 1
    LOL, exactly what I just said, you must be a much faster typist. – trumpetlicks Jun 04 '12 at 15:08
  • this is not working, i have written this code but although my imageview is going lesser zoom out than minimum scale .... any other solution will be appreciate.... – TheTiger Jun 08 '12 at 14:50
2

Inside of your gestureRecognizer, you are going to have to test and understand the current scale / size of you PDF view, and NOT zoom smaller when you are taking up the full screen.

trumpetlicks
  • 7,033
  • 2
  • 19
  • 33