【发布时间】:2014-02-05 23:05:27
【问题描述】:
我在 UIImageView 中有一个图像,它有一个缩放手势,正如您从代码中看到的那样。
我希望能够插入图像的可点击区域,而不是屏幕,所以如果我点击具有最小或最大缩放缩放的图像点,我总是返回相同的值。
我可以通过 UIGestureRecognizer 判断是否可以?为什么我不能弄清楚我是否工作。
谢谢
我的代码:
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[twoFingerTap setNumberOfTouchesRequired:2];
[img addGestureRecognizer:twoFingerTap];
float minimumScale = 0.4;//This is the minimum scale, set it to whatever you want. 1.0 = default
scroll.maximumZoomScale = 4.0;
scroll.minimumZoomScale = minimumScale;
scroll.zoomScale = minimumScale;
[scroll setContentMode:UIViewContentModeScaleAspectFit];
[img sizeToFit];
[scroll setContentSize:CGSizeMake(img.frame.size.width, img.frame.size.height)];
[control setSelectedSegmentIndex:0];
[control addTarget:self
action:@selector(action:)
forControlEvents:UIControlEventValueChanged];
//THIS IS MY RECOGNIZER ON IMAGE
UIGestureRecognizer *recognizerImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
[(UITapGestureRecognizer *)recognizer setNumberOfTapsRequired:2];
[img addGestureRecognizer:recognizer];
}
- (void)tapImage:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self.view];
NSLog(@"x %f y %f",location.x, location.y);
}
【问题讨论】:
-
好的,您已经概述了问题。你做了什么来解决它?您需要提出使用原始图像大小与当前图像大小的比例来将视图坐标转换为图像坐标的逻辑。
标签: ios objective-c image gesture