开发者

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.

this is my snippet:

...create the uibutton (btn instance)
//add gesture to button 
UILongPressGestureRecognizer *twoSecPress = [[UILongPressGestureRecognizer alloc] 开发者_StackOverflow中文版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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜