UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(allViewAction:)];html
tap.cancelsTouchesInView = YES;ios
tap.numberOfTapsRequired = 1;app
[self.bubleImageView addGestureRecognizer:tap];動畫
[tap release];ui
如上面代碼,爲一個imageview增長一個點擊手勢,在點擊很快的時候,會發現,allviewAction方法會執行屢次。而致使spa
FtPreviewFileViewController *previewFileViewController = [[FtPreviewFileViewController alloc] initWithFileContent:content previewType:FTFilePreviewTypeChat];orm
[GetIFtStatisticsPoint addActionTimesWithId:SP_FILE_RECEIVEFILE_DOWNLOADSUC_OPENFILE];htm
FtRootViewController* vc = [[FtAppDelegate shareAppDelegate] rootViewCtrl];get
UIView* curView = nil;animation
[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) {
}];
在屢次點擊時,就不會彈出多個界面了。