ios - UITapGestureRecognizer on multiple UIView (scrollview subviews) -
i have set scrollview , bench of uiview
(scrollview subviews) gestures on them:
(id element in array) { customview *view = [[customview alloc] init]; [view setframe:cgrectmake(x, 16, self.view.frame.size.width, self.view.frame.size.height)]; [self.scrollview setcontentsize:cgsizemake(scrollcontentsizewidth, self.scrollview.frame.size.height)]; uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(selectview:)]; [self.view settag:[[element valueforkey:@"id"] integervalue]]; [self.view addgesturerecognizer:tap]; view.userinteractionenabled = yes; [self.scrollview addsubview:view]; scrollcontentsizewidth +=110; x += 110; }
the called method when view touched:
-(void)selectview:(uitapgesturerecognizer *)recognizer{ nslog(@"id : %i",recognizer.view.tag);//always last assigned value in loop above }
so how fix that? uitapgesturerecognizer
seems affected last view only.
replace line
[self.view addgesturerecognizer:tap];
with
[view addgesturerecognizer:tap];
Comments
Post a Comment