nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12k stars 2.58k forks source link

Vertical Swipe gesture when in horizontal scroll mode #524

Open vijaydogra opened 10 years ago

vijaydogra commented 10 years ago

Is there any way by which I can add my added view a swipe gesture of vertical swipe, still having a horizontal scroll active? The reason being, I have a requirement where in I need to have a scroll view and when swiped up or down, should perform certain other actions. Is this possible?

Thanks, VJ

vijaydogra commented 10 years ago

This is the code for reference

- (UIView *)carousel:(__unused iCarousel *)carousel placeholderViewAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    //create new view if no view is available for recycling
    if (view == nil)
    {
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 300.0f)];
        ((UIImageView *)view).image =[UIImage imageNamed:@"1.png"];
        view.contentMode = UIViewContentModeCenter;
        UISwipeGestureRecognizer *swipeTop = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [swipeTop setDirection:UISwipeGestureRecognizerDirectionUp];
        UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
        [swipeTop setDirection:UISwipeGestureRecognizerDirectionUp];
        [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
        [view setUserInteractionEnabled:YES];
        [view addGestureRecognizer:swipeTop];
        [view addGestureRecognizer:swipeDown];
   }
    return view;
}

- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
   if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
        NSLog(@"Down Swipe");
    }

    if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"Up Swipe");
    }
}
nicklockwood commented 10 years ago

Try using the UISwipeGestureRecognizerDelegate methods. There is a shouldRecognizeSimultaneouslyWithGesture method. If you return YES from that, it should pass through the horizontal swipes to iCarousel.

vijaydogra commented 10 years ago

I have tried it with shouldRecognizeSimultaneouslyWithGesture, however, there vertical swipes are somehow blocked.

I then later found a blog post which explained iCarousel and had a sample project with version 1.8 beta 15. I copied same stuff onto my project and with the current pasted code that am using, the swipes are now detected.

Am not sure as to how much change has been done from version 1.8 beta 15 and the current version. However, for now, my requirement for showing the horizontal scroll with vertical swipes detection is achieved.

Thank you for your reply and also for the beautiful code and utility to be used :)

billylo1 commented 7 years ago

@vijaydogra : I am trying to adopt a similar approach... would you mind sharing a pointer to your sample? thx, Billy

vijaydogra commented 7 years ago

@billylo1 - That was around 3 years ago, however, I managed to get my working code (then). I am attaching the zip file for my modified library, hopefully it should still be working (as I have not checked it with latest XCode) https://www.dropbox.com/s/gclbmmy1faa2zpb/Carousel.zip?dl=0 Let me know if this would suffice your request.

Thank you, VJ

billylo1 commented 7 years ago

@vijaydogra appreciate the quick response... will report back shortly.