★ TouchArcade needs your help. Click here to support us on Patreon.

Pinch Issues

09-30-2009, 04:36 AM
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Pinch Issues

Hey guys,
So I implemented pinching. When I hold the option key and pinch outwards it works, but when I loaded it on my iPhone I can't pinch.

Does anyone have these issues or know how to solve it? I'm following the chapter in "Beginning iPhone Development".

09-30-2009, 08:33 AM
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
By the way, I'm using "Beginning iPhone Development" and they have provided a class...

#include "CGPointUtils.h"
#include <math.h>

#define pi 3.14159265358979323846
#define degreesToRadian(x) (pi * x / 180.0)
#define radiansToDegrees(x) (180.0 * x / pi)
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) {
	CGFloat deltaX = second.x - first.x;
	CGFloat deltaY = second.y - first.y;
	return sqrt(deltaX*deltaX + deltaY*deltaY );
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
	CGFloat height = second.y - first.y;
	CGFloat width = first.x - second.x;
	CGFloat rads = atan(height/width);
	return radiansToDegrees(rads);
	//degs = degrees(atan((top - bottom)/(right - left)))
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
	CGFloat a = line1End.x - line1Start.x;
	CGFloat b = line1End.y - line1Start.y;
	CGFloat c = line2End.x - line2Start.x;
	CGFloat d = line2End.y - line2Start.y;
	CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
	return radiansToDegrees(rads);
And so I use touchesEnded to do:

if([touches count] == 2)
		NSArray *twoTouches = [touches allObjects];
		UITouch *first = [twoTouches objectAtIndex:0];
		UITouch *second = [twoTouches objectAtIndex:1];
		CGFloat currentDistance = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
		if(initialDistance == 0)
			initialDistance = currentDistance;
if(currentDistance - initialDistance > kMinimumPinchDelta)
			//Outward Pinch
And somehow it's not responding. I can do it in the simulator by holding the option key, but it doesn't work on my iPhone. I know it's not my pinching technique cause someone else has tried it and it doesn't work for them...

Thanks for your help.
09-30-2009, 10:24 AM
Joined: Apr 2009
Location: Pennsylvania
Posts: 998
Did you configure your app to support multitouch? Been a while since I set this up in my projects that use it, but it's a gui checkbox you need to check rather than something that would appear in your source code.

Barring that, try one of Apple's ready-to-use projects that supports multitouch, and confirm that you can get it working on an iDevice.