简体   繁体   English

在 UILongPressGestureRecognizer 之后如何识别在视图上按下了哪个按钮

[英]How to recognize which button is pressed on the view after an UILongPressGestureRecognizer

I want to capture the frame or some proprieties(a frame or tag of a UIButton in this case) after a UILongPressGestureRecognizer is fired.我想在触发UILongPressGestureRecognizer后捕获frame或某些UILongPressGestureRecognizer (在这种情况下是UIButton的框架或tag )。

this is my snippet:这是我的片段:

...create the uibutton (btn instance)
//add gesture to button 
UILongPressGestureRecognizer *twoSecPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(setProductToButton:)];
            [twoSecPress setMinimumPressDuration:2];
            [btn addGestureRecognizer:twoSecPress];
            [twoSecPress release];
btn.tag=INDEX;

and this is the method:这是方法:

    - (void)setProductToButton:(UILongPressGestureRecognizer *)recognizer {
          if (recognizer.state == UIGestureRecognizerStateBegan) {
              for (UIButton *selButt in [self.scrollView subviews]) {
                  if(selButt.selected){//THIS IS ALWAYS FALSE
                     NSLog(@"%d",selButt.tag);
          } 
       }
   }
 }

It seems that the state of the button still has not changed.似乎按钮的状态仍然没有改变。 Any suggestion?有什么建议吗?

Are there any methods to recognize what is the last element tapped/selected?是否有任何方法可以识别点击/选择的最后一个元素是什么?

在你setProductToButton法, recognizer.view属性是被按下的按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在网格视图中按下了哪个按钮 - Which button is pressed in grid view 如何确定按下了哪个按钮? - How do I identify which button was pressed? 如何识别按下了哪个键,自定义键盘以及选择了哪个文本字段 - how to recognize which key is pressed custom keypad and which text field is selected UILongPressGestureRecognizer如何将当前视图更改为另一个视图控制器? - how can a UILongPressGestureRecognizer change the present view to another View Controller? 按下识别标签按钮即可移至下一个响应者 - Recognize tab button pressed to move to next responder 在不同视图中按下另一个按钮时如何更改按钮的文本 - How to change text of a button when another button is pressed in a different view UILongPressGestureRecognizer不删除视图 - UILongPressGestureRecognizer not removing view 按下按钮时显示子视图。 (按操作系统Windows“开始”按钮时出现的类似视图 - Show a subview when button is pressed. (Something like view which appears when operating system Windows “start” button is pressed 按下按钮后如何替换按钮中的图像以保留为新图像? - How to replace an image in a button to remain as the new image after the button is pressed? iPhone-如何确定自定义UITableViewCell中的哪个按钮被按下 - iPhone - How to determine in which cell a button was pressed in a custom UITableViewCell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM