I have a new gesture, (touch, drag onto other, release) which I would like to have behave the same as touchUpInside or touchDown or any of that list that pops up when you tie in IBActions in interface builder. (I.e. I want my custom ones on that list so I can tie them to IBActions)
Is there a way to do this or do I need to programmatically tie things together?
Update: The Next Best Thing
Here’s a very stripped down version of what I did that de-coupled my object from any other particular class, in case anyone else tries to accomplish this:
@interface PopupButton : UIView {
}
//These are the replacement "IBAction" type connections.
@property (nonatomic) SEL tapAction;
@property (nonatomic, assign) id tapTarget;
@property (nonatomic) SEL dragAction;
@property (nonatomic, assign) id dragTarget;
@end
@implementation PopupButton
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//Here we'll say I detected the event I called "drag".
if (!(self.dragTarget && self.dragAction)) {
NSLog(@"No target for drag.");
abort();
} else {
[self.dragTarget performSelector:self.dragAction];
}
//And here I detected the event "tap".
if (!(self.tapTarget && self.tapAction)) {
NSLog(@"No target for single tap.");
abort();
} else {
[self.tapTarget performSelector:self.tapAction];
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
@end
Now to set this up, in the view controller I wanted to tie these actions I put this instead:
- (void)viewDidLoad
{
[equalsPopupButton setTapTarget:self];
[equalsPopupButton setTapAction:@selector(equalsPress)];
[equalsPopupButton setDragTarget:self];
[equalsPopupButton setDragAction:@selector(isNamingResult)];
}
Not as elegant obviously as option+drag, but it gets the job done without making my code all rigid and attached. Hope this helps someone.
It is not possible to tie the functions this way. You should use an auxiliary function in code and call it from the IBaction function and the gesture recognizer function.