How to detect Fingersize with IOS?
@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):
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
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/
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.