iOS 屏蔽双击事件

来源:互联网 发布:vb教程ppt 编辑:程序博客网 时间:2024/05/16 06:07

直接上代码

  • 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

0 0
原创粉丝点击