UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(allViewAction:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
[self.bubleImageView addGestureRecognizer:tap];
[tap release];
如上面代码,为一个imageview增加一个点击手势,在点击很快的时候,会发现,allviewAction方法会执行多次。而导致
FtPreviewFileViewController *previewFileViewController = [[FtPreviewFileViewController alloc] initWithFileContent:content previewType:FTFilePreviewTypeChat];
[GetIFtStatisticsPoint addActionTimesWithId:SP_FILE_RECEIVEFILE_DOWNLOADSUC_OPENFILE];
FtRootViewController* vc = [[FtAppDelegate shareAppDelegate] rootViewCtrl];
UIView* curView = nil;
[previewFileViewController.view setFrame:CGRectMake(78, IOS7_MARGIN, 946, 748)];
[previewFileViewController setViewFrame];
[vc.view addSubview:previewFileViewController.view];
curView = previewFileViewController.view;
curView.frame = CGRectMake(946, IOS7_MARGIN, 946, 748);
[UIView animateWithDuration:1.5f animations:^{
curView.frame = CGRectMake(78,IOS7_MARGIN, 946, 748);
} completion:^(BOOL finished) {
}];
这个代码段也会执行多次。这是为何呢?
原来cancelsTouchesInView为YES,表示当Gesture Recognizers识别到手势后,会向hit-test view发送 touchesCancelled:withEvent:消息来取消hit-test view对此触摸序列的处理,这样只有Gesture Recognizers能响应此触摸序列,hit-test view不再响应。如果为NO,则不发送touchesCancelled:withEvent:消息给hit-test view,这样会使Gesture Recognizers和hit-test view同时响应触摸序列。
就是说cancelsTouchesInView为YES后,并且这个点击效果已经产生 了,才不会继续接受新的点击响应,否则系统会认为没有收到点击效果,会继续接受点击效果继续响应点击方法。
所以我们将点击的响应展现新界面的方法里面的动画时间改短一些,让界面及时的弹出来。在多次点击视图的时候,就不会多次接收点击了。因为界面弹出后cancelsTouchesInView会立刻起作用,不再接受新的点击效果。
于是将
[UIView animateWithDuration:1.5f animations:^{
curView.frame = CGRectMake(78,IOS7_MARGIN, 946, 748);
} completion:^(BOOL finished) {
}];
改成
[UIView animateWithDuration:0.01f animations:^{
curView.frame = CGRectMake(78,IOS7_MARGIN, 946, 748);
} completion:^(BOOL finished) {
}];
在多次点击时,就不会弹出多个界面了。