Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tap to zoom and double tap to zoom out in iOS?

Tags:

I'm developing an application to display a gallery of UIImages by using a UIScrollView, my question is, how to tap to zoom and double tap to zoom out, how does it work when handling with UIScrollView.

like image 411
Bruno Avatar asked Jan 25 '12 19:01

Bruno


People also ask

How do I zoom in and zoom out on my iPhone?

Adjust the magnification: Double-tap the screen with three fingers (without lifting your fingers after the second tap), then drag up or down. Or triple-tap with three fingers, then drag the Zoom Level slider.

How do I get my iPhone camera to zoom out?

On all models, open Camera and pinch the screen to zoom in or out. On iPhone models with Dual and Triple camera systems, toggle between 0.5x, 1x, 2x, 2.5x, and 3x to quickly zoom in or out (depending on your model). For a more precise zoom, touch and hold the zoom controls, then drag the slider right or left.

How do I zoom in on my iPhone without touching it?

You can see larger onscreen controls on an iPhone with Display Zoom. Go to Settings > Display & Brightness > Display Zoom.

Can you multitask on zoom on iPhone?

Zoom has updated their app to support split screen.


1 Answers

You need to implement UITapGestureRecognizer - docs here - in your viewController

- (void)viewDidLoad {     [super viewDidLoad];             // what object is going to handle the gesture when it gets recognised ?     // the argument for tap is the gesture that caused this message to be sent     UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)];     UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];      // set number of taps required     tapOnce.numberOfTapsRequired = 1;     tapTwice.numberOfTapsRequired = 2;      // stops tapOnce from overriding tapTwice     [tapOnce requireGestureRecognizerToFail:tapTwice];      // now add the gesture recogniser to a view      // this will be the view that recognises the gesture       [self.view addGestureRecognizer:tapOnce];     [self.view addGestureRecognizer:tapTwice];  } 

Basically this code is saying that when a UITapGesture is registered in self.view the method tapOnce or tapTwice will be called in self depending on if its a single or double tap. You therefore need to add these tap methods to your UIViewController:

- (void)tapOnce:(UIGestureRecognizer *)gesture {     //on a single  tap, call zoomToRect in UIScrollView     [self.myScrollView zoomToRect:rectToZoomInTo animated:NO]; } - (void)tapTwice:(UIGestureRecognizer *)gesture {     //on a double tap, call zoomToRect in UIScrollView     [self.myScrollView zoomToRect:rectToZoomOutTo animated:NO]; } 

Hope that helps

like image 98
GWed Avatar answered Oct 10 '22 21:10

GWed