here is a snippet of my old project.
Add a UITapGestureRecognizer
to your init
method:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTapRecognized:)]; doubleTap.numberOfTapsRequired = 2; [self addGestureRecognizer:doubleTap]; [doubleTap release];
This works when you double-tap in your view.
- (void)doubleTapRecognized:(UITapGestureRecognizer*)recognizer { [self zoomToPoint:[recognizer locationInView:content]]; } - (void)zoomToPoint:(CGPoint)location { float zoomScaleBefore = self.zoomScale; if (location.x<=0) location.x = 1; if (location.y<=0) location.y = 1; if (location.x>=content.bounds.size.width) location.x = content.bounds.size.width-1; if (location.y>=content.bounds.size.height) location.y = content.bounds.size.height-1; float percentX = location.x/content.bounds.size.width; float percentY = location.y/content.bounds.size.height; [self setZoomScale:10.0 animated:YES]; float pox = (percentX*self.contentSize.width)-(self.frame.size.width/2); float poy = (percentY*self.contentSize.height)-(self.frame.size.height/2); if (pox<=0) pox = 1; if (poy<=0) poy = 1; [self scrollRectToVisible: CGRectMake(pox, poy, self.frame.size.width, self.frame.size.height) animated:(self.zoomScale == zoomScaleBefore)]; }
user207616
source share