I have a UIScrollViewone used inside a custom class that has subclasses UIView. Inside this scrollview, I added several other custom objects (all subclasses UIView):) /
UITapGestureRecognizer *tap;
for (int count = 0; count < ColorSchemeCount; count++) {
[self managePageAdditions];
ColorScheme *scheme = [[ColorScheme alloc]
initWithFrame:[self determineSchemeCircleFrameFromCount:pageCheck]
title:[self getColorSchemeTitleFromIndex:pageCheck]
colors:[self getColorSchemeFromIndex:pageCheck]];
scheme.tag = pageCheck;
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(schemeTouchedAtIndex:)];
tap.cancelsTouchesInView = NO;
[scheme addGestureRecognizer:tap];
[self.scrollView addSubview:scheme];
if(pageCheck > 0) needsNextPage = (pageCheck % kSchemesPerPage == 0);
needsNextPage ? pageCheck = 0 : pageCheck++;
}
And then I try to see the tag ColorSchemeto respond accordingly:
- (void)schemeTouchedAtIndex:(UITapGestureRecognizer *)gesture{
CGPoint touchPointInSuperview = [gesture locationInView:self.scrollView];
ColorScheme *touchedView = (ColorScheme *)[self.scrollView hitTest:touchPointInSuperview withEvent:nil];
NSLog(@"%li", (long)touchedView.tag);
}
And no matter what I do, it always registers the tag as zero .
A few observations:
- I can confirm that the tags are set correctly and everything is
ColorSchemeadded just fine. - I also have it
tap.cancelsTouchesInView = NO, so it UIScrollViewwon’t swallow all the touches. locationInView self self.scrollView, . , , , UIView.
.