我添加在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是控制器主視圖的子視圖,但我試圖將目標更改爲主視圖,這也沒有任何區別。
你實現了哪個委託方法? – Wain
我忘記實現shouldRecognizeSimultaneouslyWithGestureRecognizer:因爲我也使用平移手勢識別器。我添加了它,它現在可以工作。 – Gruntcakes