【发布时间】:2011-07-18 18:38:00
【问题描述】:
我有一个 UIScrollView,里面有一个带有图像的 UIImageView。我希望能够缩放并且仍然能够获得 UIImage 的坐标。我的图像的坐标大于 iPhone 屏幕 600x800,使用当前方法,我只能在 iPhone 屏幕上获得坐标。如何获取已点击的 UIImage 上实际位置的坐标?
这是我到目前为止所得到的:
- (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];
//imageV.userInteractionEnabled = YES;
//[imageV addGestureRecognizer:tapGesture];
//CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
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];
}
【问题讨论】:
标签: iphone uiscrollview uiimageview uiimage uigesturerecognizer