UITapGestureRecognizer na UILabels w podglądzie UIScrollView nie działa

Mam problem z tym, że mój UITapGestureRecognizer na moim UILabels w widoku treści w moim UIScrollView nie nazywa go metodami.

Hierarchia widoków wygląda następująco:

scrollView (UIScrollView)contentView (UIView)testLabel (UILabel) - tutaj jest dołączony UITapGestureRecognizer

Poddałem kod destylacji do przykładu, aby podkreślić problem

// Set scrollview size - Added in Storyboad
[scrollView setContentSize:CGSizeMake([arrayOfVerbs count]*self.view.frame.size.width, scrollView.contentSize.height)];
[scrollView setCanCancelContentTouches:YES]; // Tried both yes and no
[scrollView setPagingEnabled:YES];

// Add content view
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)];
[scrollView addSubview:contentView];

// Add test UILabel
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
[testLabel setBackgroundColor:[UIColor redColor]];
[testLabel setText:@"Test touch"];
[testLabel setUserInteractionEnabled:YES];
[contentView addSubview:testLabel];

// Add gesture recogniser
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playSound:)];
singleTap.numberOfTapsRequired = 1;
[testLabel addGestureRecognizer:singleTap];

I to jest metoda, którą powinien wywoływać urządzenie do rozpoznawania gestów

- (void)playSound:(UITapGestureRecognizer *)sender {

    NSLog(@"play sound");

    if(sender.state == UIGestureRecognizerStateEnded)
    {
        int pronounNumber = [sender.view tag];
        int exampleNumber = (int)sender.view.frame.origin.x%(int)self.view.frame.size.width;

        NSLog(@"Pronoun is %i and example is %i", pronounNumber, exampleNumber);
    }
}

Ta metoda nigdy nie jest wywoływana, gdy próbowałem dotknąć UILabel.

Próbowałem ustawić właściwość canCancelContentTouches na TAK i NIE na widoku przewijania, jak sugeruje towątek, ale nadal nie działa.

Dziwne jest to, że jeśli dodam UILabel poza scrollView, wtedy narzędzie rozpoznawania gestów działa! Więc problem występuje tylko w moim contentView, który jest podglądzie mojego scrollView.

Używam automatycznego układu, jeśli to może być jakaś różnica?

Dzięki!

questionAnswers(3)

yourAnswerToTheQuestion