Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Fingersize with IOS?

Is it possible to detect the fingersize in an IOS Application? I've read in the documentation:

Notes: A finger on the screen affords a much different level of precision than a mouse pointer. When a user touches the screen, the area of contact is actually elliptical and tends to be offset below the point where the user thinks he or she touched. This “contact patch” also varies in size and shape based on which finger is touching the screen, the size of the finger, the pressure of the finger on the screen, the orientation of the finger, and other factors. The underlying Multi-Touch system analyzes all of this information for you and computes a single touch point.

Source: https://web.archive.org/web/20121120152010/http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html

So, does that mean theres no possibility with the SDK to detect the physical fingersize? What I want to accomplish: I need virtual "buttons" in my OpenGL ES Application. And if someone hold the iPhone like a gamepad, he will probalbly use one finger for two buttons (rolling off the thumb). I hope its understandable what I mean...

Any ideas?

like image 886
Constantin Avatar asked Jul 27 '11 10:07

Constantin


3 Answers

@fichek is right, there is no regular way to get the size of fingertips.

However, I had used a 'strange' way in my previous project to do it, and it just works ;-)

1.Tell our user to put two fingers on the screen together, the closer the better(like the two-finger scrolling gesture on Mac): enter image description here

2.Get the two CGPoints from UITouches in the touchesBegan:withEvent: method;

3.Now we have CGPoint fingertip1center and fingertip2center, so:

float fingertip_Diameter=fabsf(fingertip1center.x-fingertip2center.x);

4.The fingers are really close and we may ignore the tiny difference in width , so dX == the real width of a singel finger.

5.The width(dX) and the fingertipsize are proportional, we can simply use

float fingertip_Size=M_PI*(dX/2)*(dX/2);

or find a better algorithm to meet your needs ;-)

6.Once we got the size (actually we only care about the diameter), its easy to implement a method to optimize touching by testing various surrounded points, e.g.:

#define kTestLevelOne 5 //Testing 5 points:origin,left,right,up,down
#define kTestLevelTwo 9 //And the other 4 corners
-(BOOL)testSurroundingPoints:(CGPoint *)pt
{
   float prob_x[kTestLevelTwo]={0,-dX/2,dX/2,0,0,-dX/2,-dX/2,dX/2,dX/2};
   float prob_y[kTestLevelTwo]={0,0,0,dX/2,-dX/2,dX/2,-dX/2,dX/2,-dX/2};

   for(int i=0;i<kTestLevelTwo;i++)
   {
      if([self gotItAtX:pt.x+prob_x[i] andY:pt.y+prob_y[i]]==YES)
       {
           NSLog(@"Got It!");
           Return YES;
           //Or break; We don't need to try more points!
       }
   }
   return NO;
}

Hope these can help!

Yichao Peak Ji

like image 163
PeakJi Avatar answered Nov 07 '22 15:11

PeakJi


Actually, there's a way to get the touch radius:

-(void)touchesBegan:(NSSet *)touches 
      withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGFloat touchSize = [[touch valueForKey:@"pathMajorRadius"] floatValue];
    NSLog(@"touch size is %.2f", touchSize);
}

Source: http://easyplace.wordpress.com/2013/04/09/how-to-detect-touch-size-in-ios/

like image 34
crishoj Avatar answered Nov 07 '22 13:11

crishoj


iOS does all sorts of finger size/angle/location calculation behind the scenes, so there is no way to detect anything but the computed location of a touch. However, that's more than enough info for you to know which part of gamepad the finger is on.

As @marcus mentioned, you should implement the touchesMoved:withEvent: method and check for touch's location to determine if it's over left/right/top/bottom/center or whatever "buttons" you want to have.

like image 27
Filip Radelic Avatar answered Nov 07 '22 15:11

Filip Radelic