iOS 屏蔽双击事件

时间:2022-01-10 16:02:21

直接上代码

  • BMUIApplication 继承UIApplication
#import <UIKit/UIKit.h>

@interface BMUIApplication : UIApplication
@property (assign,nonatomic) BOOL IgnoringEvents;
@end
  • BMUIApplication的实现
#import "BMUIApplication.h"

@implementation BMUIApplication
- (void)sendEvent:(UIEvent *)event
{
    self.IgnoringEvents = NO;
    if (event.type == UIEventTypeTouches) {
        if ([[event.allTouches anyObject] phase] == UITouchPhaseBegan) {
            if(event.allTouches.count > 1){
                self.IgnoringEvents = YES;
            }
            else{
                self.IgnoringEvents = NO;
            }
        }
    }
    if(!self.IgnoringEvents){
        [super sendEvent:event];
    }

}
@end
  • main.m 修改
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "BMUIApplication.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
    return UIApplicationMain(argc, argv, NSStringFromClass([BMUIApplication class]), NSStringFromClass([AppDelegate class]));
    }
}
  • 如果单纯屏蔽事件的话可以用
[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

参考资料

http://blog.csdn.net/sakulafly/article/details/18766339
http://blog.csdn.net/sakulafly/article/details/18792631