Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to implement it yourself using some basic math.</p> <pre><code>(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; </code></pre> <p>Those are the delegate methods that you need to implement in your application.</p> <p>You need to get the distance between the two touches, then calculate the changes in distance in your own code.</p> <p>The mathematical equation you use to get the distance is called the <a href="http://en.wikipedia.org/wiki/Dot_product" rel="noreferrer">dot product</a></p> <p>I just want to point out that the equation they use in the cited tutorial is incorrect. I have updated it to include the absolute value that is missed in the tutorial.</p> <p>This is the dot product: </p> <pre><code>- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint { float xDist = fromPoint.x - toPoint.x; float yDist = fromPoint.y - toPoint.y; float result = sqrt( pow(xDist,2) + pow(yDist,2) ); return result; } </code></pre> <p><strong>Edit:</strong> I made a mistake in my previous answer....it's been a while since I've done any of that kind of math.</p> <p>If you don't square root the result, you won't get the true distance between the points. This is called calculating the magnitude between two vectors.</p> <p>This is the proper way to do it. If you want to omit the sqrt, you will not have the exact distance between the two points.</p> <p>If you don't square the answer, your code will work but it will be using measurements that are much larger than the actual values. So in the future if you need to get the distance between the two points, it will return something like 90000 instead of the actual pixel distance which would be 300px.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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