我在 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。在上面的代码中没有设置手势识别器的委托,但添加了它并将其设置为 self 并没有任何区别。
scrollView 是控制器主视图的子视图,但我尝试将目标更改为主视图,这也没有什么区别。