【轉】iOS學習之iOS禁止Touch事件,ios禁止touch事件
iOS程式中有時會有需要禁止應用接收Touch的要求(比如動畫進行時,防止觸摸事件觸發新方法)。
一、一般有兩種:
1、弄個遮罩層,禁止互動;
2、使用UIApplication中的方法進行相關的互動設定,方法如下:
// 開始禁止互動- (void)beginIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS(""); // nested. set should be set during animations & transitions to ignore touch and other events// 結束禁止互動- (void)endIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");// 是否禁止了互動#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
二、具體在代碼裡的實現如下:
1、禁止互動
if (![[UIApplication sharedApplication] isIgnoringInteractionEvents]) //禁止互動 [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
2、由禁止變為啟用互動
if ([[UIApplication sharedApplication] isIgnoringInteractionEvents]) [[UIApplication sharedApplication] endIgnoringInteractionEvents]; //啟用互動