Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling user interaction of the current view on screen

My app has many views and their respective controllers. Now I have a set of model classes with business logic in them. One of the model classes(subclass of NSObject) has the responsibility of managing security. It's intended function is to listen for a particular instruction from a web server and if a 'disable' message arrives from server, disable the UI for any further usage.

Now the 'disable' message can arrive at any instant during the functioning of the app and any view can be visible on screen. How do I determine which view is visible to the user(from my model class) and disable user interaction for it?

like image 933
Vin Avatar asked Oct 24 '11 15:10

Vin


People also ask

How do I turn off interaction in Swiftui?

Put your view to be "tap disabled" into a Group then apply the modifier . allowsHitTesting(false) to disable interaction with any view inside the group. To enable interaction switch the modifier to true.


2 Answers

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.

like image 147
Gotschi Avatar answered Sep 23 '22 21:09

Gotschi


Here is the code for Swift 3

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

Slight update to the syntax

like image 41
mightyr Avatar answered Sep 22 '22 21:09

mightyr