Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To fix your problem scrap your "handleTouches" method. The first thing you do in your handleTouches method, is switch it on the touchPhase, but that is already given to you. If you recieve the touch in touchesBegan, you know the touch is in UITouchPhaseBegan. By funneling touches from the four touch methods into one method, you are defeating the purpose of having four delegate methods.</p> <p>In each of those methods, Apple gives you an opportunity to deal with a different phase of the current touch.</p> <p>The second thing is that you don't need to search the event for the current touch, it is given to you as a parameter: touches.</p> <p>An event is comprised of sets of touches. For convienence, you are given the current touches even though it can also be found within event.</p> <p>So, in touchesBegan, you start tracking a touch.</p> <pre><code> - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{ NSString *startPoint = NSStringFromCGPoint([[touches anyObject] locationInView:self]); NSDictionary * touchData = [NSDictionary dictionaryWithObjectsandKeys: startPoint, @"location", touches, @"touch"] [startingLocations addObject:touchData]; } </code></pre> <p>I'm using an array of dictionaries to hold my touch data. </p> <p>Try to seperate your code and move it into the appropriate touch method. For direction, Apple has a couple sample projects that focus on touches and show you how to setup those methods.</p> <p>Remember, these methods will get called automatically for each touch during each phase, you don't need to cycle through the event to find out what happened.</p> <p>The pointer to each set of touches remains constant, just the data changes. </p> <p>Also, I would read the iPhone OS programming guide section on event handling which goes into greater depth of what I said above with several diagrams explaining the relationship of touches to events over time.</p> <p>An excerpt:</p> <blockquote> <p>In iPhone OS, a UITouch object represents a touch, and a UIEvent object represents an event. An event object contains all touch objects for the current multi-touch sequence and can provide touch objects specific to a view or window (see Figure 3-2). A touch object is persistent for a given finger during a sequence, and UIKit mutates it as it tracks the finger throughout it. The touch attributes that change are the phase of the touch, its location in a view, its previous location, and its timestamp. Event-handling code evaluates these attributes to determine how to respond to the event.</p> </blockquote>
 

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