我有一个问题,当我尝试使用以下方法将我的手势识别器添加到许多滑块时
UIGestureRecognizer *sliderTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)] autorelease];
[slider addGestureRecognizer:sliderTap];
[slider2 addGestureRecognizer:sliderTap];
...
仅在应用中应用了最后一个。我一次在屏幕上最多有10个滑块。有没有办法让一个UIGestureRecognizer适用于所有人?
答案 0 :(得分: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];
参考检查this