ios - recognize the different view tag via UITapGestureRecognizer -
i use code below add touch tapgesturerecognizer on 3 views.
uitapgesturerecognizer *anuitapgesturerecognizer = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(dosomething:)]; view1.tag=1; [view1 addgesturerecognizer:anuitapgesturerecognizer]; view2.tag=2; [view2 addgesturerecognizer:anuitapgesturerecognizer]; //... view3.tag=3; [view3 addgesturerecognizer:anuitapgesturerecognizer];
same as
but if tap view1, view2, view3, code below output 1, 2, 3
- (void)dosomething:(uitapgesturerecognizer *)tap { nsstring *s= [nsstring stringwithformat:@"%ld", (long)tap.view.tag]; nslog(@"%@",s); }
s returns 3
your comment welcome
you can't this .you need make different uitapgesturerecognizer
instances each uiview's
.
Comments
Post a Comment