【发布时间】:2013-10-08 22:42:22
【问题描述】:
我在 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 是控制器主视图的子视图,但我尝试将目标更改为主视图,这也没有区别。
【问题讨论】:
-
你实现了哪些委托方法?
-
我忘了实现 shouldRecognizeSimultaneouslyWithGestureRecognizer: 因为我也在使用平移手势识别器。我添加了它,它现在可以工作了。
标签: ios