Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal UISwipeGestureRecognizer in subview of UIScrollView ? (UIScrollView only needs to recognize vertical scrolling)

I have a UIScrollView where I added a subview. The scrollview scrolls fine vertically and that is all it should do. I would now like to recognize left/right swipes in the subview with the help of a UISwipeGestureRecognizer. I know it is possible, but I have not come across a solution and several tries have been unsuccessful.

like image 848
the_critic Avatar asked Jan 25 '26 09:01

the_critic


1 Answers

Try these:

  • Set the delegate of your UIGestureRecognizer and

  • Implement shouldRecognizeSimultaneouslyWithGestureRecognizer:

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

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

Hope this helps

like image 118
FD_ Avatar answered Jan 27 '26 22:01

FD_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!