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

发布于 2024-11-08 13:30:00 字数 1002 浏览 0 评论 0原文

我想在 UILongPressGestureRecognizer 之后捕获 frame 或一些属性(在本例中是 UIButton 的框架或 tag) code> 被解雇。

这是我的代码片段:

...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;

这是方法:

    - (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);
          } 
       }
   }
 }

看来按钮的状态仍然没有改变。 有什么建议吗?

有没有任何方法可以识别最后点击/选择的元素是什么?

I want to capture the frame or some proprieties(a frame or tag of a UIButton in this case) after a UILongPressGestureRecognizer is fired.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2024-11-15 13:30:00

setProductToButton 方法中,recognizer.view 属性是按下的按钮。

In your setProductToButton method, the recognizer.view property is the button that was pressed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文