How to detect Fingersize with IOS?
Asked Answered
B

3

7

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?

Burtie answered 27/7, 2011 at 10:28 Comment(4)
You could just handle (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event and check the locationInView of the given touches. So you would have one gamepad view/area and check which part is hit/covered on touchesMoved.Zyrian
But I can retrieve only one CGPoint from locationInView, and not for both button positions. So iOS seems to detect only one "blob" at all (not both - a big thumb isn't detected as 2 touches)...Burtie
You could still an area within the gamepad view which would be valid for both buttons - think of the buttons intersecting each others.Zyrian
There is a draft in W3C that requires OS exposes those properties to developer. docs. Hopefully in future Safari implements that and we can use it!Ireful
O
11

@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

Osteotomy answered 4/8, 2011 at 15:24 Comment(0)
J
5

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/

Jenelljenelle answered 22/6, 2014 at 19:35 Comment(0)
D
2

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.

Departure answered 3/8, 2011 at 21:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.