3

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.

0

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Would this method only be called once? I want the length if time touch is on the UIView, so need the touchStart and touchEnd events.
the tapGesture argument has a state such as UIGestureRecognizerStateBegan or UIGestureRecognizerStateEnd i would use this to detect the two touch events you are interested
make sure u read the official doc on the tapgesture though: developer.apple.com/library/ios/#documentation/uikit/reference/…
Thanks, I shall try this method in the morning.
1

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)

2 Comments

I did think of this, but I think it will be very hard to move the UIView the same speed as the scroll view
@Darren Hmmm. What about a UIButton set to custom and with an alpha bg set to 0.0? Also, if you add a UIView, it doesn't necessarily have to move with the UIScrollView...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.