UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)];
[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];
[tapGesture release];
在上面的代码中,只能识别view2上的点击。如果我注释掉第三行,那么点击view1会被识别。如果我是对的,你只能使用手势识别器一次,我不确定这是一个错误还是它只是需要一些更多的文档。
我使用下面的方法来解决这个问题。
for (UIButton *aButton in myButtons) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration=1.0;
[aButton addGestureRecognizer:longPress];
[longPress release];
}
然后在我的handleLongPress方法中,我只是设置一个UIButton等于手势识别器的视图,并根据该按钮分支我所做的事情
- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
UIButton *whichButton=(UIButton *)[gesture view];
selectedButton=(UIButton *)[gesture view];
....
}
我使用下面的方法来解决这个问题。
for (UIButton *aButton in myButtons) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration=1.0;
[aButton addGestureRecognizer:longPress];
[longPress release];
}
然后在我的handleLongPress方法中,我只是设置一个UIButton等于手势识别器的视图,并根据该按钮分支我所做的事情
- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
UIButton *whichButton=(UIButton *)[gesture view];
selectedButton=(UIButton *)[gesture view];
....
}