Darren
Darren

Reputation: 10398

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.

Upvotes: 3

Views: 852

Answers (2)

jpcguy89
jpcguy89

Reputation: 217

Perhaps reordering your views so that a view that has a touch recognizer object associated with it is what the app recognizes. Move it in the document outline to the top (scroll view)

Upvotes: 1

tiguero
tiguero

Reputation: 11537

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.

Upvotes: 4

Related Questions