KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to create an app where UIButtons can be draged and dropped when a UILongPressGestureRecognizer gesture is fired. I have: UIGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; And - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer { CGPoint location = [recognizer locationInView:self.view]; switch (recognizer.state) { case UIGestureRecognizerStateBegan: //NSLog(@"handleLongPress: StateBegan"); break; case UIGestureRecognizerStateChanged: if(location.y > 75.0 && location.x > 25 && location.x < 300) button.frame = CGRectMake(location.x-25, location.y-15, 50, 30); break; case UIGestureRecognizerStateEnded: //NSLog(@"handleLongPress: StateEnded"); break; default: break; } } This works great with one button (namely the ivar button ). How can I send to the handleLongPress function the current button that is being pressed? In other words, I would like to do something like the following where I pass in sender - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer:(id)sender { CGPoint location = [recognizer locationInView:self.view]; switch (recognizer.state) { case UIGestureRecognizerStateBegan: //NSLog(@"handleLongPress: StateBegan"); break; case UIGestureRecognizerStateChanged: if(location.y > 75.0 && location.x > 25 && location.x < 300) sender.frame = CGRectMake(location.x-25, location.y-15, 50, 30); break; case UIGestureRecognizerStateEnded: //NSLog(@"handleLongPress: StateEnded"); break; default:
Tags (comma-separated)
Save Edits
Cancel