terra incognita

Understanding MWPhotoBrowser

2015-04-01 02:04

MWPhotoBrowser : UIViewController

MWZoomingScrollView : UIScrollView

- (void)handleDoubleTap:(CGPoint)touchPoint;

Function

Zoom in (2x) or zoom out.

Callers

- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch;
- (void)handleDoubleTap:(UITouch *)touch;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

Implementation

- (void)handleDoubleTap:(CGPoint)touchPoint {
    
    // Cancel any single tap handling
    [NSObject cancelPreviousPerformRequestsWithTarget:_photoBrowser];
    
    // Zoom
    if (self.zoomScale != self.minimumZoomScale && self.zoomScale != [self initialZoomScaleWithMinScale]) {
        
        // Zoom out
        [self setZoomScale:self.minimumZoomScale animated:YES];
        
    } else {
        
        // Zoom in to twice the size
        CGFloat newZoomScale = ((self.maximumZoomScale + self.minimumZoomScale) / 2);
        CGFloat xsize = self.bounds.size.width / newZoomScale;
        CGFloat ysize = self.bounds.size.height / newZoomScale;
        [self zoomToRect:CGRectMake(touchPoint.x - xsize/2, touchPoint.y - ysize/2, xsize, ysize) animated:YES];

    }
    
    // Delay controls
    [_photoBrowser hideControlsAfterDelay];
    
}

Reference

Basic Zooming Using the Pinch Gestures