我有两个带有“UILongPressGestureRecognizer”的按钮,为此,我这样做:
Fot按钮1:
-(IBAction)seleccionar46:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[self.button1 addGestureRecognizer:longpressGesture];}
对于按钮2:
-(IBAction)seleccionar46:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[self.button2 addGestureRecognizer:longpressGesture];}
在“longpressGesture”中,我需要区分button1和button2,但我无法做到......
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{//Here i need do the differentation}
谢谢大家!
最好的问候。
答案 0 :(得分:6)
您可以使用view
的{{1}}属性,因此如果保存对两个按钮的引用,则可以检查是否相等。
所以,如果你有
UIGestureRecognizer
然后将识别器添加到您可以在处理程序中执行的按钮
@interface blah
{
UIButton *buttonOne;
UIButton *buttonTwo;
}
希望有所帮助