iOS程序中有时会有需要禁止应用接收Touch的要求(比如动画进行时,防止触摸事件触发新方法),一般有两种,一种是弄个遮罩层,禁止交互,另一种就是UIApplication中的方法了,如下:
//开始禁止交互
- (void)beginIgnoringInteractionEvents; // nested. set should be set during animations & transitions to ignore touch and other events
//结束禁止交互
- (void)endIgnoringInteractionEvents;
//是否禁止了交互
- (BOOL)isIgnoringInteractionEvents; // returns YES if we are at least one deep in ignoring events
于是就有了禁止交互时用
if (![[UIApplication sharedApplication] isIgnoringInteractionEvents]) //禁止交互
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
由禁止变为启用交互时用
if ([[UIApplication sharedApplication] isIgnoringInteractionEvents])
[[UIApplication sharedApplication] endIgnoringInteractionEvents]; //启用交互