2013-07-01 37 views
0

我有一個tableview A的行條目自定義繼承到一個GridView B(實際上使用開源MMGridView)。 gridView/scrollView的子視圖單元格使用touchesBegan/TouchesEnd來檢測它們的選擇。觸摸事件在自定義塞格期間排隊?

我正在使用故事板,並且自定義段落由tableView中的didselectrowatindexpath/performsegue動畫和啓動。

問題是,一旦選擇了tableview行,其他的水龍頭正在排隊並傳遞到單個gridCells。

在自定義的segue中,我試過設置destinationviewcontroller.view.userInteractionEnabled = NO;然後在destinationViewController的viewDidAppear中重新啓用它。這不起作用,排隊的觸摸事件仍然傳遞給gridView的子單元。

如何在自定義動畫過渡期間刷新或取消似乎已經排隊的任何觸摸事件?

編輯:刪除自定義segue似乎停止「排隊」觸摸事件的行爲。或者,也許現在的賽格發生的速度足夠快,以免在賽事中發生觸摸事件?爲了完整起見,這裏是我的習慣uistoryboardsegue,給我的問題:

#import "QuartzCore/QuartzCore.h" 

@implementation TTOCustomSegue 

-(void)perform { 

UIViewController *sourceViewController = (UIViewController*)[self sourceViewController]; 
UIViewController *destinationController = (UIViewController*)[self destinationViewController]; 
//destinationController.view.userInteractionEnabled = NO; 

CATransition* transition = [CATransition animation]; 
transition.duration = .4; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
transition.type = kCATransitionFade; 
transition.subtype = nil; 

[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];  
[sourceViewController.navigationController pushViewController:destinationController animated:NO];  
} 
@end 
+0

看上去發生的事情是,即使動畫未完成,目標視圖控制器仍在運行並踢踢和接收觸摸事件。啊。爲了在轉換/動畫期間真正地禁止用戶交互,看起來我需要使用不同的轉換方法,例如, animateWithDuration有一個完成塊,我可以重新啓用用戶交互,或者一個允許設置UIViewAnimationOptionAllowUserInteraction的動畫方法。不幸的是,改變segues的動畫方法是另一種蠕蟲。 –

回答

0

不應該有任何排隊事件。確保你不會阻塞主線程。

要在動畫過程中完全阻止事件處理,在UIApplication上有一些有用的方法。

[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

[[UIApplication sharedApplication] endIgnoringInteractionEvents]; 

這些方法是非常有用的,如果你需要開始一個延遲的動畫,你不想在延遲階段的任何用戶操作。

+0

謝謝,動畫本身並沒有延遲,我貼了上面的動畫代碼。我想嘗試一下你的建議,但如果使用支持完成塊的方法實現過渡動畫,則實現起來會更容易一些?我將檢查自定義賽段是否可以使用animateWithDuration之類的東西... –

相關問題