Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect touches on a UIView inside UIScrollView preferably with Interaction disabled

I have a UIScrollView with some UIViews in it. What I am trying to do, is catch the touches events when the UIViews are touched/untouched.

The problem I am having, is the UIScrollView seems to swallow all the touch events, especially if you hold for too long on a UIView.

I preferably want the UIScrollView to have userInteraction disabled as it scrolls automatically.

Is this possible?

I have tried subclassing the UIViews but the touches events are never called in it.

like image 248
Darren Avatar asked Jan 29 '26 01:01

Darren


1 Answers

You can attach a tapGesture to your scrollview with something along those lines:

   UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureUpdated:)];
   tapGesture.delegate = self;
   tapGesture.numberOfTapsRequired = 1;
   tapGesture.numberOfTouchesRequired = 1;
   [self addGestureRecognizer:_tapGesture];

then in your - (void)tapGestureUpdated:(UITapGestureRecognizer *)tapGesture method this is your responsability to determine the location of the touch and find out if there was a picking on one of your subviews. You could call then a method on a delegate that notify that a specific view has been touched.

like image 95
tiguero Avatar answered Jan 30 '26 15:01

tiguero



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!