Block user interaction with main views

In my application, I have an overlay view that is displayed when some processing and network interaction occurs. This is just a translucent view (a subclass of UIView) with a loading indicator on it filling the entire screen.

I want none of the basic views to get user interaction (for example, you should not scroll the main table view, the button should not be pressed).

What is the best way to do this from the overlay view?

+7
source share
4 answers

Just set the userInteractionEnabled property to the userInteractionEnabled property to display the YES overlay. This will cause all touch events to appear in the overlay view and will not be passed to the base views.

+10
source

Just set the userInteractionEnabled property of your translucent overlay to YES.

+4
source

I think the best way is to use these 2 methods:

 [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; [[UIApplication sharedApplication] endIgnoringInteractionEvents]; 

before performing heavy processing operations and after their completion, respectively.

+2
source

Just make sure that the overlay and all its parent views do not have userInteractionEnabled set to NO, are not hidden, and do not have alpha less than 0.01. Then user touches will interact with the overlay, not with the views visible behind it. Also keep in mind that it will not block interaction in a region that is not covered by its supervisors: even if your view covers the entire screen, if its parent object is only 10x10, then it blocks interaction only inside this 10x10 region, to which it extends parent.

You may also need to make sure that resignFirstResponder is called for any existing first responder, or that the user can still interact with it using the keyboard.

+1
source

All Articles