0

In an iOS app, I have an UIView that contains a UIScrollView, and an overlay UIImageView with some transparency.
The overlay view is on top of the UIScrollView and has userInteractionEnabled set to YES.
I can properly receive touch events on the overlay, but the scrollview does not get them anymore.

When userInteractionEnabled si set to NO on the overlay, then I can properly pan in the UIScrollView but obviously the overlay does not get the touch events anymore.

How to be able to pass touch events from the overlay to the scrollview so I can still scroll or pan the scrollView?

I've tried this from the overlay, but it does not work:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    <...>
    [myParent.myScrollView touchesMoved:touches withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    <...>
    [myParent.myScrollView touchesBegan:touches withEvent:event];
}
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89

1 Answers1

1

Create a custom UIView class , implement this method and set it to the overlay view in IB

func point(inside point: CGPoint, 
  with event: UIEvent?) -> Bool {
    return true
 }
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • My overlay class is indeed a subclass of UIImageView and created programmatically (hence no IB). I've tried adding your code in my overlay class, and now see I have to assess when to send back YES or NO. – Laurent Crivello May 06 '18 at 10:19