Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do the following: Make an NSTimer that will start up when the app starts or in viewDidLoad and also make a boolean. </p> <p>For example:</p> <pre><code>//Declare the timer, boolean and the needed IBActions in interface. @interface className { NSTimer * timer; bool g; } -(IBAction)theTouchDown(id)sender; -(IBAction)theTouchUpInside(id)sender; -(IBAction)theTouchUpOutside(id)sender; //Give the timer properties. @property (nonatomic, retain) NSTimer * timer; </code></pre> <p>Now in your implementation file (.m):</p> <pre><code>//Synthesize the timer @synthesize timer; //When your view loads initialize the timer and boolean. -(void)viewDidLoad { g = false; timer = [NSTimer scheduledTimerWithInterval: 1.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES]; } </code></pre> <p>Now make an IBAction for "Touch Down" set the boolean to lets say true. Then make another IBAction button for "Touch Up Inside" and "Touch Up Outside" assign the boolean to false. </p> <p>For example:</p> <pre><code>-(IBAction)theTouchDown { g = true; } -(IBAction)theTouchUpInside { g = false; } -(IBAction)theTouchUpOutside { g = false; } </code></pre> <p>Then in that NSTimer method, put the following:(assume g is the boolean you have declared)</p> <pre><code>-(void) targetmethod:(id)sender { if (g == true) { //This is for "Touch and Hold" } else { //This is for the person is off the button. } } </code></pre> <p>I hope this simplifies everything... I know it still uses a timer but there is not another way.</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