Question

I have a UIScrollView which displays a pdf page. I already implemented a single tap gesture to hide/show a tool bar on screen and a double tap for zooming in and out... the problem is that the zooming in is always on the center of the page and I want it to zoom where the user last tapped. I already save the CGPoint of the last touch but I don`t know how to use it on the zoom in... here's some of my code, any help is appreciated, thx.

CODE UPDATED (working)

@implementation PDFScrollView //custom UIScrollView
{
    CGPoint lastTouch;
    CGFloat ZOOM_MIN;
    CGFloat ZOOM_MAX;
    UIView* PDFView;
}

-(void) gestureDoubleTap{
    if ([self zoomScale]==ZOOM_MAX) {
        [self setZoomScale:ZOOM_MIN animated:YES];
    }else {
        [self zoomToRect:CGRectMake(lastTouch.x, lastTouch.y, 0, 0) animated:YES]
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    lastTouch = [(UITouch*)[touches anyObject] locationInView:self.PDFView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.PDFView;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
    if ([self zoomScale]<ZOOM_MIN) {
        [self setZoomScale:ZOOM_MIN animated:YES];
    }else if ([self zoomScale]>ZOOM_MAX){
        [self setZoomScale:ZOOM_MAX animated:YES];
    }
}
Was it helpful?

Solution

use zoomToRect:animated method of UIScrollView

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