1

I have a scrollview. Inside the scrollview, I have three subviews, A, B, C. When I click on subview A, I want to get either its tag value or know which view I've clicked. I've gone through many codes and blogs, but couldn't find a solution for it.

    - (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {}
    - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{} //This function is not working with sub view.

Tried these methods but didn't solve my problem.

4

1 に答える 1

5

を使用しUITapGestureRecognizerます。A、B、C ビューのそれぞれにタップ ジェスチャ レコグナイザーを追加し、デリゲートをビュー コントローラーに設定すると、タップごとに通知されます。

UITapGestureRecognizer* tgrA = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[viewA addGestureRecognizer:tgrA];
...

-(void) handleTapGesture:(UIGestureRecognizer *)sender 
{
    //sender.view.tag will give you what you need.
}

タップ ジェスチャ認識エンジンの詳細については、 https ://developer.apple.com/library/ios/documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html をご覧ください。

于 2013-10-18T02:23:09.673 に答える