Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get touch size in iOS?

Tags:

ios

size

touch

I understand that this response clearly states that this is not possible without a private function call. Therefore, according to Apple's terms, this approach cannot be used on an App Store app.

However, some apps already seem to use this function call:

  • Penultimate for actual palm rejection without a predefined rejection area like in Note Taker HD
  • Virtuoso for pressure sensitivity, which they call "TrueVelocity 2"
  • GarageBand also for pressure sensitivity

Clearly, this approach is already widely used in App Store apps despite Apple's restrictions.

tl;dr What is the private function call on iOS to get touch size?

like image 613
Albert Armea Avatar asked Jan 14 '12 19:01

Albert Armea


People also ask

How do I see app size in IOS?

Go to Settings > General > [Device] Storage. You might see a list of recommendations for optimizing your device's storage, followed by a list of installed apps and the amount of storage each one uses. Tap an app's name for more information about its storage.

How do I change the screen size on my iPhone?

Go to Settings > Display & Brightness > Display Zoom. Select Larger Text to make all the text on iPhone larger. Tap Done, then tap Use Zoomed.

What is the default text size on iPhone?

The default text is 100%, but you can make it as small as 80% normal size or as large as 310%.


2 Answers

With iOS8, you can access the touch.majorRadius property, which is a CGFloat, grows in multiples of 10.45 and is proportional to the radius of the touched area in Millimeters. touch.majorRadiusTolerance is the second property which can be used with iOS8 and gives the accuracy of the touch radius information. In my measurements it was always half of the majorRadius step size.

On the iPad Pro the touchscreen is three times more sensitive and picks up the weak signal from the Apple pencil which is below the reporting threshold on older iPad models. The touch radius of the Pencil is reported as 0.25, while even the slightest finger contact will report as 20.84 or more.

Use it like this within your UIView method:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

// Regular multitouch handling.
    [super touchesBegan:touches withEvent:event];

    CGPoint center = [touch locationInView:self];
    NSLog(@"Touch detected at %6.1f | %6.1f", center.x, center.y);
    CGFloat radius = [touch majorRadius];
    NSLog(@"Radius = %5.1f; lower limit = %5.1f; upper limit = %5.1f", radius, radius-touch.majorRadiusTolerance, radius+touch.majorRadiusTolerance);
}
like image 112
Peter Kämpf Avatar answered Sep 20 '22 17:09

Peter Kämpf


Size and pressure are two different animals. Penultimate most likely tests for a large amount of touches in a certain area (palms have a large area after all, generate tons of touches).

Touch "size" does not exist. IOS touch events are generated when a finger contacts the screen. The OS then takes a center point from the touch and that's what you get. It's not a CGRect, it's a CGPoint.

Pressure is 'easier' though. see here for a workaround: Tap pressure strength detection using accelerometer

And while I see you're in the market for private API's, github hosts a number of class dumps: http://github.com/kennytm/iphone-private-frameworks and https://github.com/nst/iOS-Runtime-Headers

like image 37
CodaFi Avatar answered Sep 21 '22 17:09

CodaFi