0

我有一个问题,当我尝试使用以下方法将手势识别器添加到许多滑块时:

UIGestureRecognizer *sliderTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)] autorelease];
[slider addGestureRecognizer:sliderTap];
[slider2 addGestureRecognizer:sliderTap];
...

只有最后一个应用在应用程序中。我一次在屏幕上最多有 10 个滑块。有没有办法让一个 UIGestureRecognizer 适用于他们?

4

1 回答 1

0

您不能将单个 UIGestureRecognizer 分配给多个滑块,您需要为每个滑块创建单独的。

UIGestureRecognizer *sliderTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)] autorelease];
UIGestureRecognizer *sliderTap2 = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped2:)] autorelease];

[slider addGestureRecognizer:sliderTap];
[slider2 addGestureRecognizer:sliderTap2];

供参考检查这个

于 2013-10-07T10:04:52.460 回答