I have a UIScrollView and inside it there is a UIImageView with an image. I would like to be able to scale and still get the UIImage coordinates. My image has more coordinates than the iPhone 600x800, and using the current method, I get the coordinates only on the iPhone. How can I get the coordinates of the actual location on the UIImage that was used?
This is what I still have:
- (void) loadView {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
UIImage *mapImage = [UIImage imageNamed:@"Map1.png"];
imageV = [[UIImageView alloc] initWithImage:mapImage];
scrollV = [[UIScrollView alloc] initWithFrame:imageV.frame];
scrollV.contentSize = CGSizeMake(imageV.frame.size.width, imageV.frame.size.height);
[scrollV addGestureRecognizer:tapGesture];
[scrollV addSubview:imageV];
scrollV.userInteractionEnabled = YES;
scrollV.maximumZoomScale = 5;
scrollV.minimumZoomScale = 0.5;
scrollV.bounces = NO;
scrollV.bouncesZoom = NO;
scrollV.delegate = self;
self.view = scrollV;
}
-(void)tapDetected:(UIGestureRecognizer*)recognizer{
NSLog(@"tap detected.");
CGPoint point = [recognizer locationInView:nil];
NSLog(@"x = %f y = %f", point.x, point.y );
}
-(UIView*) viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [[self.view subviews] objectAtIndex:0];
}
source
share