UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)];
[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];
[tapGesture release];
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,只view2识别了点击.如果我注释掉第三行,那么点击就会view1被识别出来.如果我是对的,你只能使用一次手势识别器,我不确定这是一个bug还是只需要一些文档.
我想模仿一个长按按钮,我该怎么做?我认为需要一个计时器.我明白UILongPressGestureRecognizer但是我怎么能利用这种类型呢?
我正在动态添加图像按钮到一些scrollview.他们都指向一个longPressHandler.现在,我如何获得按下哪个按钮?[sender tag]给了我添加到按钮的longGestureRecognizer标签,我无法手动设置该标签.
for (...) {
UIButton *button = [[UIButton alloc] init];
button.tag = w + h * 3;
[button addTarget:self action:@selector(imageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *gest = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(imageButtonLongPress:)];
gest.minimumPressDuration = 1;
gest.delegate = self;
[button addGestureRecognizer:gest];
[gest release];
[scrollView addSubview:button];
[button release];
}
- (void) imageButtonLongPress:(id)sender {
// how to get button tag here?
}
Run Code Online (Sandbox Code Playgroud) ios ×2
objective-c ×2
button ×1
cocoa-touch ×1
iphone ×1
long-press ×1
sender ×1
tags ×1
uibutton ×1