Carousel3D items not allowing custom gestures or taps


#1

Is there a special way to add custom gestures or taps to the item in a carousel control? The didTapItem works fine but I also need the user to tap another object i have added to the item. Nothing seems to register against any other objects.  I have no errors but receive no interaction. I do have userInteractionEnabled = YES on the items created. Any ideas?


#2

Additonally, If I add a simple button to any item in the carousel. The button cannot be tapped. Why is this? I have carousel.userInterActionEnabled = YES as well as the items created. Need some help – anyone out there?


#3

Hi,

I’ve had a look into this issue for you. As you’ve seen, by default the carousel will swallow tap gestures, but you can make use of the UIGestureRecognizerDelegate protocol if you want to change this behaviour.

To demonstrate how to do this, I’ll take the CarouselHowToTapToSelect sample project as a starting point, and then add extra tap gesture recognizers to the items in the carousel.

First of all, I extend the ViewController interface to adopt the UIGestureRecognizerDelegate protocol:

@interface ViewController () <UIGestureRecognizerDelegate>

@end

Then I implement one of the optional delegate methods:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

This means that any gesture recognizers which have the view controller as a delegate will recognize simultaneously with other recognizers. Now I can add a custom tap gesture recognizer to each of my carousel items:

-(UIView *)carousel:(SEssentialsCarousel *)carousel itemAtIndex:(int)index
{
    // Create the item...
    
    // Add a tap recognizer to the item
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [item addGestureRecognizer:tapRecognizer];
    tapRecognizer.delegate = self;
    
    return item;
}

As you can see above, I’ve made the view controller the delegate of the new tap recognizer. Now I can implement the method to call for taps:

- (void)handleTap:(UIGestureRecognizer*)sender {
    NSLog(@"Tap received!");

    // Do some work here...
}

Now, when I run the demo, my custom gesture recognizer is handled along with the normal behaviour of the carousel.

I hope that helps! There is a separate issue with UIButtons, because I don’t think you can just set the gesture recognizer delegate on a button in the same way. This should be enough to get you started with your development though.

Many thanks,

Dan