i have a transparent UIScrollView on top of another view.
the scroll view has content - text and images, used to display info.
the view behind it has some images that the user should be able to tap on. and the content over them is scrollable using the mentioned scrollview.
i want to be able to normally use the scroll view (no zoom though), but when that scroll view is not actually scrolling to let the tap events through to the view behind it.
using a combination of the touch and scroll events i can determine when to let the taps through. but the view behind it still it does not receive them.
i have tried using something like this for all touch events:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan %@", (_isScrolling ? @"YES" : @"NO"));
if(!_isScrolling)
{
NSLog(@"sending");
[self.viewBehind touchesBegan:touches withEvent:event];
}
}
but it does not work.
also in my case i cannot really apply the hitTest and pointInside solutions, given the use case that i have.
First off
UIScrollView
s only inherently recognizeUIPanGestureRecognizer
s andUIPinchGestureRecognizer
s so you need to add aUITapGestureRecognizer
to theUIScrollView
so it can recognize any tapping gestures as well:Then once you receive that tap gesture and the
handleTap:
action is triggered, you can uselocationInView:
to detect whether the tap gesture's position is in fact within the frame of one of the images below your scroll view, for example:This way, the above code is only performed if a tap gesture is recognized, your program only reacts to a tap on the scroll view if the tap location falls within an image; otherwise, you can just scroll your
UIScrollView
as usual.Here I present my complete solution that:
Here the interface:
And the Implementation:
The only extra code used is inside the
UIView+Additions.h
category, which contains the following method:Thanks
The problem is that your
UIScrollView
is consuming the event. To pass it through, you would have to disable the user's interaction on it, but it wouldn't scroll then. If you have the touches location however, you can calculate where would that fall on the underlying view, using theconvertPoint:toView:
method, and call a mathod on it by passing on theCGPoint
. From there, you can calculate which image was tapped.