Pinch Issues

Discussion in 'Public Game Developers Forum' started by kohjingyu, Sep 30, 2009.

  1. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    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".

    Thanks.
     
  2. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    By the way, I'm using "Beginning iPhone Development" and they have provided a class...

    Code:
    #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:

    Code:
    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
                            NSLog(@"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. :)
     
  3. Stroffolino

    Stroffolino Well-Known Member
    Patreon Silver

    Apr 28, 2009
    1,100
    8
    38
    Software Engineer
    Pennsylvania
    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.
     

Share This Page