Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I (how) create my own UITouch events that can be tied in to IBActions?
    text
    copied!<p>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)</p> <p>Is there a way to do this or do I need to programmatically tie things together?</p> <h2>Update: The Next Best Thing</h2> <p>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:</p> <pre><code>@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 &amp;&amp; self.dragAction)) { NSLog(@"No target for drag."); abort(); } else { [self.dragTarget performSelector:self.dragAction]; } //And here I detected the event "tap". if (!(self.tapTarget &amp;&amp; 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 </code></pre> <p>Now to set this up, in the view controller I wanted to tie these actions I put this instead:</p> <pre><code>- (void)viewDidLoad { [equalsPopupButton setTapTarget:self]; [equalsPopupButton setTapAction:@selector(equalsPress)]; [equalsPopupButton setDragTarget:self]; [equalsPopupButton setDragAction:@selector(isNamingResult)]; } </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload