这里有几个关于如何让单个 UIGestureRecognizer 识别多个视图的示例。我有这段代码,我尝试了各种方法来让它工作,但不幸的是似乎不起作用。如果有人能对此有所了解,我将不胜感激。
如果我创建多个(IBAction)函数,我能够让它工作的唯一方法,但我有多达 100 个需要移动的视图,因此需要有 100 个不同的函数。我在这里阅读了一个示例,其中可以使用标签来做到这一点,但我尝试过,不幸的是它不起作用。如果有帮助,我正在使用 XCode 4.6.1。这是下面的代码。
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{
UIView *player=recognizer.view;
int tag=player.tag;
[player addGestureRecognizer:recognizer];
if (tag!=0) {
CGPoint translation =[recognizer translationInView:self.view];
player.center=CGPointMake(player.center.x+translation.x, player.center.y+translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:player.superview];
}
}