重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//单击事件 -(void)fun1 { NSLog(@"click1"); } //双击事件 -(void)fun2 { NSLog(@"click2"); } //单击和双击方法之一 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if ([[touches anyObject] tapCount] == 1) { [self performSelector:@selector(fun1) withObject:nil afterDelay:1]; } else if ([[touches anyObject] tapCount] ==2) { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fun1) object:nil]; [self performSelector:@selector(fun2) withObject:nil afterDelay:1]; } }
int num = 0; -(void)fun1 { [NSThread sleepForTimeInterval:1]; if(num == 1) { NSLog(@"click 1"); } } -(void)fun2 { [NSThread sleepForTimeInterval:1]; if(num == 2) { NSLog(@"click 2"); } } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if([[touches anyObject] tapCount] == 1) { num = 1; NSThread * thread = [[NSThread alloc] initWithTarget:self selector:@selector(fun1) object:nil]; [thread start]; } else if([[touches anyObject] tapCount] == 2) { num = 2; NSThread * thread = [[NSThread alloc] initWithTarget:self selector:@selector(fun2) object:nil]; [thread start]; } }
原理:执行第二个方法的时候,取消第一次的方法操作
- (void)viewDidLoad { [super viewDidLoad]; //点击事件 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fun1)]; //单点触摸 tap.numberOfTouchesRequired = 1; //点击几次,如果是1就是单击 tap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:tap]; UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fun2)]; tap2.numberOfTapsRequired = 2; [self.view addGestureRecognizer:tap2]; //如果满足第二次 第一次的就取消 [tap requireGestureRecognizerToFail:tap2]; }
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:858550 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================
转载请注明出处:http://blog.csdn.net/dingxiaowei2013/article/details/10450627
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。