Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - forward all touches through a view

I have a view overlayed on top of many other views. I am only using the overaly to detect some number of touches on the screen, but other than that I don't want the view to stop the behavior of other views underneath, which are scrollviews, etc. How can I forward all the touches through this overlay view? It is a subclass of UIView.

like image 563
sol Avatar asked Oct 07 '22 10:10

sol


2 Answers

Disabling user interaction was all I needed!

Objective-C:

myWebView.userInteractionEnabled = NO;

Swift:

myWebView.isUserInteractionEnabled = false
like image 142
rmp251 Avatar answered Oct 08 '22 23:10

rmp251


For passing touches from an overlay view to the views underneath, implement the following method in the UIView:

Objective-C:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"Passing all touches to the next view (if any), in the view stack.");
    return NO;
}

Swift 5:

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    print("Passing all touches to the next view (if any), in the view stack.")
    return false
}
like image 131
PixelCloudSt Avatar answered Oct 08 '22 23:10

PixelCloudSt