yos*_*osh 4 tags iphone cocoa-touch button sender
我正在动态添加图像按钮到一些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)
Mar*_*bar 12
其中有一个view属性,UIGestureRecognizer它返回识别器所附加的视图.我认为这是你最好的选择.
- (void) imageButtonLongPress:(id)sender {
UIGestureRecognizer *recognizer = (UIGestureRecognizer*) sender;
int tag = recognizer.view.tag;
}
Run Code Online (Sandbox Code Playgroud)