0

Hi I have a UIView on top of a UIScrollView like this. The UIView is a container that is itself transparent but has many subviews which are not.

-------------------------
-   UIScrollView        -
-                       -
-     -------------     -   
-     -  UIView   -     -   
-     -------------     -     
-------------------------

The UIView is transparent but it prevents the UIScrollView from scrolling when touched. Some of the subviews are buttons so they have tap gestures that override the scrolling action but the transparent gaps in the frame of the UIView still blocks the scrolling gesture. Is there a way to prevent this from happening? I would still like to use it as a container to hold my other subviews.

Huy Nghia
  • 996
  • 8
  • 22
Math is Hard
  • 896
  • 1
  • 12
  • 24

3 Answers3

2

You should not set userInteractionEnabled to NO hence you want it intractable. I think the right way is to subclass a UIView and override - pointInside: withEvent: like below.

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    CGPoint localPoint = [self convertPoint:point fromView:self];
    for (UIView *subview in self.subviews) {
        if ([subview pointInside:localPoint withEvent:event]) {
            return YES;
        }
    }
    return NO;
}

Use this view you can interact with subviews inside the view and scroll scroll view if not touch on subviews.

Ken Kuan
  • 809
  • 6
  • 8
1

Thanks for the answers guys. But I found this solution which worked well for me:

How to get touches when parent view has userInteractionEnabled set to NO in iOS

Community
  • 1
  • 1
Math is Hard
  • 896
  • 1
  • 12
  • 24
-1

Set userInteractionEnabled to FALSE on your view inside the scroll view.

myView.userInteractionEnabled = FALSE;
rebello95
  • 8,486
  • 5
  • 44
  • 65