我在主要的UIView
([self view])上添加了一些子視圖(UITextView
)來縮放/捏和拖動它們在屏幕上。一切工作正常的一個subview
與標籤(mytextview1.tag = 1)。在主視圖中添加UIPinchGestureRecognizer並檢測子視圖上的觸摸
但是如何告訴UIPinchGestureRecognizer有多個subview
? 換句話說:如何檢測當前觸摸的subview
並給它一個標籤值? 某種類型的擊球(單指觸摸@subview
)?
我想使用主視圖的可用性的原因。我可以附上這個兩個手指gestue每subview
但他們可以是小縮放...
這裏ONE subview
與標籤的代碼:
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;
}
怎麼樣'則hitTest:withEvent:方法'? – Wain