Open vijaydogra opened 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");
}
}
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.
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 :)
@vijaydogra : I am trying to adopt a similar approach... would you mind sharing a pointer to your sample? thx, Billy
@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
@vijaydogra appreciate the quick response... will report back shortly.
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