我UITextView
在主视图UIView
([self view])上添加了一些子视图()来缩放/捏合并在屏幕上拖动它们。subview
带有标签(mytextview1.tag = 1)的 ONE 一切正常。
但是如何告诉 UIPinchGestureRecognizer 不止一个subview
呢?换句话说:如何检测当前的触摸subview
并给它一个标签值?某种hittest(一根手指触摸@ subview
)?
出于可用性原因,我想使用主视图。我可以将这两个手指手势附加在每个上,subview
但它们可以很小以进行缩放...
这里是带有标签的 ONEsubview
的代码:
UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[[self view] addGestureRecognizer:twoFingerPinch];
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"Pinch scale: %f", recognizer.scale);
mytextview1.tag = 1; // please give an idea to detect current touched subview
UITextView *myViewWithTag = (UITextView *)[self.view viewWithTag:1];
UITextView *myViewWithTag = (UITextView *)recognizer.view;
CGPoint location = [recognizer locationInView:recognizer.view];
NSLog(@"location: %@", NSStringFromCGPoint(location));
UIFont *font = [myViewWithTag font];
CGFloat pointSize = [font pointSize];
NSString *fontName = [font fontName];
pointSize = ((recognizer.velocity > 0) ? 1.0 : -1.0) * 1 + pointSize;
if (pointSize < 13) pointSize = 13;
if (pointSize > 120) pointSize = 120;
[myViewWithTag setFont:[UIFont fontWithName:fontName size:pointSize]];
CGRect frame = myViewWithTag.frame;
frame.size.height = myViewWithTag.contentSize.height;
myViewWithTag.frame = frame;
}