0

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Mat
  • 7,613
  • 4
  • 40
  • 56
  • 1
    Hi, Mat. If i understand the question right way, you could use the "tag" property of the "UIView" class which is inherited in UIButton. Is "self"-object, in your case, a main view controller? If so, you can define a property to store the tag and set it with the tag of the element (Button) tapped. If you want to get the view to which your gesture recognizer is attached to you can use "recognizer" parameter of the handler function, it should have a "view" property. – danny_23 May 20 '11 at 18:11

1 Answers1

4

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

highlycaffeinated
  • 19,729
  • 9
  • 60
  • 91