Question

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?

Was it helpful?

Solution

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]);
  ...

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top