[Switch] iOS learning: iOS disables Touch events and ios disables touch events
In iOS apps, there are sometimes requirements to prohibit applications from receiving Touch (for example, when an animation is ongoing, preventing Touch events from triggering new methods ).
I. There are two types:
1. Create a mask layer to prohibit interaction;
2. Use the method in UIApplication to set the interaction as follows:
// Start to disable interaction-(void) beginIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS (""); // nested. set shoshould be set during animations & transitions to ignore touch and other events // end disable interaction-(void) endIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS (""); // whether interaction is disabled # if UIKIT_DEFINE_AS_PROPERTIES @ property (nonatomic, readonly, getter = isIgnoringInteractionEvents) BOOL ignoringInteractionEvents; // returns YES if we are at least one deep in ignoring events # else-(BOOL) isIgnoringInteractionEvents; // returns YES if we are at least one deep in ignoring events # endif
2. The specific implementation in the Code is as follows:
1. Disable Interaction
If (! [[UIApplication sharedApplication] isIgnoringInteractionEvents]) // disable interaction [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
2. Change from disabled to enabled Interaction
If ([[UIApplication sharedApplication] isIgnoringInteractionEvents]) [[UIApplication sharedApplication] endIgnoringInteractionEvents]; // enable interaction