Disabling user interaction of the current view on screen

You could add a delegate in the class that is listening to the server and so when it gets that message it just calls disable on whomever its delegate is. Whichever view is showing to get the message as well as normal execution until the message is received. If it is a singleton just set the view as the delegate on viewWillAppear.

Another viable option is to use the notification center. So when your class gets the disable message just do

[[NSNotificationCenter defaultCenter] postNotificationName:@"disableView" object:nil];

and when your views load add them to listen

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disableView:) name:@"disableView" object:nil];

Then stop listening when they aren't needed.

Subclassing UIViewController and implementing the disable functionality and then subclassing that class in all other view controllers would eliminate the duplication of code.


I've done something very similar to this. I disable all user interaction by placing a translucent black view over everything else, which visually distinguishes the fact that the entire UI is disabled, and blocks all touch events. I usually just add this view to the window class after I've added the view controller's view to the window, and then just hide it when it's not needed.


Here is the code for Swift 3

UIApplication.shared.beginIgnoringInteractionEvents() 
UIApplication.shared.endIgnoringInteractionEvents()

Slight update to the syntax


Maybe you want the whole application to not react at all?

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

use [[UIApplication sharedApplication] endIgnoringInteractionEvents]; to revert this (credits to nerith)

same for Swift:

UIApplication.sharedApplication().beginIgnoringInteractionEvents()
UIApplication.sharedApplication().endIgnoringInteractionEvents()

and Swift 3/4

UIApplication.shared.beginIgnoringInteractionEvents()
UIApplication.shared.endIgnoringInteractionEvents()

edit for iOS 13: beginIgnoringInteractionEvents is deprecated in iOS13

just make a new full size View and lay it over your current view. that will allow you to block any user interaction.