What is the best method for creating a layer to catch touch events?

I need to put up an info screen above the main interface, but I need it to be alpha'd so you can see the interface underneath it. However, when I touch across the screen, the interface underneath is still running.

What is the best method for intercepting the touch events so they don't pass through? I tried to add a custom UIButton the size of the screen, but that didn't work either :(

There is too much code to post here unfortunately. The view is hundreds of lines long, but the important bit is adding the overlayed subview, which is like this:

InfoScreen *infoScreen = [[UIView alloc] initWithFrame:self.view.frame];
UIButton *invisibleButton = [UIButton buttonWithType:UIButtonTypeCustom];
invisibleButton.frame = self.view.frame;

[self.view addSubview:invisibleButton];
[self.view addSubview:infoScreen];

I am using touchesBegan, touchesMoved, touchesEnded and touchesCancelled in the view below. Is this possibly why the touches are getting through?




If you want to stop everything from responding (for example for a time-based block), you can use

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];


[[UIApplication sharedApplication] endIgnoringInteractionEvents];

It won't work if you need a touch to cancel this state ;-). In that case, a transparent UIView on top of your background will get the job done. If it doesn't, post some code.

Need Your Help

Using Protractor how to run multiple spec files without closing browser for each spec file

node.js testing jasmine protractor angularjs-e2e

I'm using page object design pattern in my automation tests. I have spec file per page object. When the tests run, browser restarts in between spec files where it asks to login again. But what I'm ...