Passing touch information to a UIScrollView under another UIView

I have a UIScrollView under a transparent UIView. I need to transfer all pans and taps to scroll mode (which scrolls horizontally only). A regular UIView uses a subclass of UIPanGestureRecognizer to track vertical brackets ( Subclass found here ). In the overlay view, I override the touch event methods to pass them to the UIScrollView.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; [self.scrollView.panGestureRecognizer touchesBegan:touches withEvent:event]; [self.scrollView.singleTapGesture touchesBegan:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; [self.scrollView.panGestureRecognizer touchesCancelled:touches withEvent:event]; [self.scrollView.singleTapGesture touchesCancelled:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; [self.scrollView.panGestureRecognizer touchesEnded:touches withEvent:event]; [self.scrollView.singleTapGesture touchesEnded:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; [self.scrollView.panGestureRecognizer touchesMoved:touches withEvent:event]; [self.scrollView.singleTapGesture touchesMoved:touches withEvent:event]; } 

Overlay view, vertical panorama works fine. In UIScrollView, cranes also work just fine. Scrolling though, not so much. The scroll view scrolls about three points and then stops (as the horizontal pan continues). If I let go of the speed, the scroll view then raises that speed and ends the scroll.

What are the possible problems causing a scroll view to stop scrolling and then get speed?

+7
source share
3 answers

From the code you posted, I assume that you are not doing anything with a transparent UIView .. then why don't you just set userInteractionEnabled = NO; ??

+2
source

Here are lighter solutions that worked well for me:

In a transparent UIView (let it be called OverlayView), make the width and height as 0 (so that the view is no longer technically on top of the UIScrollView) and set clipToBounds = NO (so that the contents of the OverlayView are still displayed on top of the UIScrollView).

  self.OverlayView.clipsToBounds = NO; CGRect frame = self.OverlayView.frame; self.OverlayView.frame = CGRectMake(frame.origin.x, frame.origin.y, 0, 0); 

Note that if OverlayView contains interactive controls (such as the button above), they will no longer work. You will need to move it to your own view over the UIScrollView.

0
source
 #import "CustomUiView.h" @implementation CustomUiView.h -(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event{ return NO; } @end 

The view you do not want to interact with. create a custom UIView class and use this custom view as the top view that returns NO in the pointInside method. Then the touch will be automatically closed. In your case, your transparent UIView will be a subclass of CustomUiView UIView.

0
source

All Articles