Let's assume the following setup:
There is a horizontal-only scrolling, transparent UIScrollView
(rectangle with blueish background and red border) and a infinite number of UIImageView
instances (reddish squares) being subviews of the same UIView
(self.view
).
The UIScrollView
is being brought to front by
[self.view bringSubviewToFront:scrollView]
in the containing UIViewController
.
The following shall be achieved: The UIScrollView
should receive the left/right swipe gestures to scroll horizontally, whereas the UIImageViews
covert by the UIScrollView
should receive swipe gestures with direction up/down, which are added as follows:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpGestureHandler:)];
swipeUpGesture.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown;
[imageView addGestureRecognizer:swipeGesture];
This works when the UIImageView
is not covered by the UIScrollView
, but obviously does not work when the UIScrollView
is in front of said views.
To summarize, the UIScrollView
should forward the up/down swipe event / gesture to the specific underlying UIImageView
, but still receive the regular left/right swipe event / gesture for horizontal scrolling.
From what I read in the documentation it would be easy to solve if the UIImageViews
would be contained inside the UIScrollView
- however, that is not possible in this setup, and I'm pretty sure there has to be a solution to solve this problem.
Any hints are appreciated, thank you.
I've found a solution for this issue. While I was unable to forward the swipe up/down gestures to the image views behind the scrollview, I've now added gesture recognisers with direction up/down to the scrollview. In the gesture recognisers actions, I determine the point of the gesture within the window and hittest the window's first view for these point with a nil event. In the custom scrollview, I overwrote the hittest message to return NO with an empty event so the appropriate imageview would eventually be identifier. Once I got the imageview lying behind the scrollview at the point of the gesture, I was able to perform the appropriate action on my imageview.
I'm not sure whether this is the finest solution for this issue, however I wasn't able to build a better one after hours of investigation and experimenting. This setup might be a bit unusual and therefor tricky. Your input is still appreciated in case you have anything to add.