Juan
Juan

Reputation: 627

how to know if UITapGestureRecognizer has been add to subview

I adding subviews programmatic. for each subview I'm adding a gesture reconognizer:

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake((position*1024)+200,0,image.size.width,image.size.height);
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
                                               initWithTarget:self action:@selector(singleFingerTap:)];
    singleFingerTap.numberOfTapsRequired = 1;
    [imageView addGestureRecognizer:singleFingerTap];
    [singleFingerTap release];

but the tap is not responding how can I verify the gesture has been add it to the subview ?

Upvotes: 4

Views: 1728

Answers (1)

chown
chown

Reputation: 52738

Add this after your code:

NSLog(@"imageView.gestureRecognizers: %@", [imageView.gestureRecognizers description]);

If you have properly added gestureRecognizers it will print the description of each to the console. If not, it will show (NULL) or an empty array in the console.


You can also set the gesture recognizer delegate:

[singleFingerTap setDelegate:self];

Then add the delegate method and set a break point to make sure it is getting called:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"gestureRecognizerShouldBegin: called");
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"shouldReceiveTouch: called");
    return YES;
}

Upvotes: 3

Related Questions