2013-10-08 50 views
0

我添加在viewDidLoad中一對夫婦輕掃手勢識別的但是指定的選擇不被稱爲:輕掃手勢識別不觸發方法調用

UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)]; 
swipeGestureRight.numberOfTouchesRequired = 1; 
swipeGestureRight.direction = (UISwipeGestureRecognizerDirectionRight); 
[self.scrollView addGestureRecognizer:swipeGestureRight]; 

UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)]; 
swipeGestureLeft.numberOfTouchesRequired = 1; 
swipeGestureLeft.direction = (UISwipeGestureRecognizerDirectionLeft); 
[self.scrollView addGestureRecognizer:swipeGestureLeft]; 

如果我改變選擇器@selector(crashAtRunTimeWithUndefinedMethod :)那麼沒有任何反應 視圖控制器繼承自UIGestureRecognizerDelegate。設置手勢識別器的代表不是在上面的代碼中完成的,而是添加了手勢識別器並將其設置爲自己並沒有任何區別。

scrollView是控制器主視圖的子視圖,但我試圖將目標更改爲主視圖,這也沒有任何區別。

+0

你實現了哪個委託方法? – Wain

+0

我忘記實現shouldRecognizeSimultaneouslyWithGestureRecognizer:因爲我也使用平移手勢識別器。我添加了它,它現在可以工作。 – Gruntcakes

回答

1

UIScrollView已經具有預配置的手勢識別器,用於檢測滑動(以及其他手勢,如平移)。記錄包含識別UIScrollView的手勢的數組,您將看到它們。

這並不是說您無法將其他手勢識別器添加到UIScrollView,但您必須小心。在我自己的應用程序中,我向UIScrollView添加了輕敲手勢識別器,沒有問題,因爲它不與任何預先配置的手勢識別器競爭。

+2

真的不知道該如何解決問題... – Wain