UITextView
メイン([セルフ ビュー]) にいくつかのサブビュー ( ) を追加してUIView
、拡大縮小/ピンチして画面上でドラッグしました。subview
タグ (mytextview1.tag = 1) を持つONEでは、すべてが正常に機能します。
しかし、複数あることを UIPinchGestureRecognizer に伝えるにはどうすればよいsubview
でしょうか。言い換えれば、現在のタッチを検出しsubview
てタグ値を与える方法は? ある種のヒットテスト (1 本の指で @ に触れるsubview
) ですか?
使いやすさの理由から、メイン ビューを使用したいと考えています。この 2 本指のジェスチャをすべてに付けることsubview
ができますが、スケーリングするには小さすぎる可能性があります...
subview
タグ付きのONE のコードは次のとおりです。
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;
}