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
.
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.
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.
You can see larger onscreen controls on an iPhone with Display Zoom. Go to Settings > Display & Brightness > Display Zoom.
Zoom has updated their app to support split screen.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With