how to extract more touch points from UIResponder? - ios

When I touch a UIView with the base of my finger tip, and get the touch point using touches anyObject, I get a single touch point, even though the base of my finger tip has an area that touches a lot many points. Is there a way to get all those points? If there is no such way, how are simple paint apps implemented in ios?

You are getting the only point / touch. Each touch is related to a single finger. This is controlled by iOS.
'Simple' drawing / painting apps use the path traced by the touch points together with the current line drawing width and texture to create lines or bezier paths.
If you're trying to create a drawing app with some form of pressure sensitivity then you'd need to integrate with a 3rd party stylus (like this one)

Related

Get Raw Data, Such as Touch Shape, for UITouch Events

I'd like to get the raw touch data from the iPad. The main goal is to be able to detect the actual shape of the touch on the screen. For example if I use a touch conductive piece of foam shaped like a triangle on the screen I want to be able to tell it's a triangle. If only a corner of that foam touches the screen I want to know the actual shape that it's making on the screen.
I've done a bit of digging so far and I understand that UITouch can provide an approximate touch radius, but that would only give me a circle where I want whatever abstract shape touches the screen.
I found an old question that asks something similar and it points to GSEvent, but I'm not sure how to get this data from the GSEvent or even how to get the GSEvent from the UIEvent.
I don't mind if this uses private API, I'd just like to figure out if this is doable at all.

What are the ways to create a custom shape touch detection?

Hi I'm making a baseball app and I want from users to input strike zone on a grid like this:
How can I build the visual part so that I won't have too much trouble with implementation of a tap gesture recogniser. It'll be great if I can make this resizable so it will look great on many different devices.
With the touch gesture I need to handle so kind of recognizing position in two ways.
In which section the touch was detected.
What are the approximate coordinates inside this section.
This data will be saved on a cloud and can be later used to show the dot on this grid on other devices.
Is there a way to detect touch in a non rectangular shapes? Maybe with Bezier Paths.
Do you have a suggestion how ti appear on screen without using whole grid as a image. I'd rather divide it in Outer grid and the Inner grid somehow and than create all the pieces in each of this grids. 8 pieces in outer and 9 in inner grid.
You can start with UIBezierPath and its method containsPoint:, although this method "does not take into account the line width used to stroke the path." (link), it is also true for UIBezierPath.
Refer further to this article.

How to enforce touching within a ring shape using iOS SpriteKit?

I need to have the player moving the finger within the shaded ring:
The program should be able to detect "out of boundary" events once the finger moves outside the ring (shown in red).
Any best practices for doing this in SpriteKit, ideally in Swift? Thanks!
You could draw your shapes using CGPath, then use CGPathContainsPoint to determine if the touched locations are inside or outside the path.
You can use CGPaths like this in SpriteKit using SKShapeNode.

More precisse shape or mask for a SKSpriteNode object

I'm bulding a simple application using SpriteKit for iOS 7 / 8 but I'm having some issues with my sprites when I try to touch and launch some events from one of two nodes that are too close to each other.
When I try to touch one of them, I end up touching the upper layer one square mask, and if I change the [self addChaild:] order it happens the same but with the other one.
I want to know if I can create a more precisse mask for my nodes so this won happen when I try to touch them. I know I can create a physics world and a physics body for each of them to control Collision Detection but I don't know if this is the right approach.
BTW... I'm using the methods touchesBegan:withEvent: and touchesEnded:withEvent: for touching events detection.
PD: if you need any more info about my implementation please let me know.

Quartz2D good way to Draw point or line on touch?

I'm trying to develop an app that requires drawing based on user touch. I'm using Quartz2D and CoreGraphics for drawing, now I'm wondering what's a good way to manage the points that i'm drawing? Currently I'm adding each touchMoved point to an array and setNeedsDisplay them on every move. This lags the system very fast. So Therefore I'm wondering if anyone know a good way to draw smoothly with user touch for a good amount of time? Thanks!
Touch events are fired very frequently. since quartz2d is slow your system will saturate.
several options
Switch to opengl ^^ (bu that is an overkill)
don't do a draw on every single event. put you touch to sleep (acutally thats an android soluiton so I'm not sure its good for Iphone), only draw 1 out of x lines.
store the coordinates of your touch somewhere and when your app is ready to refresh the ui, get the current values stored and do you draw.
another solution I had put in place is to test if the new position had actually moved of more that a certain amount from the las draw (lets say 1~3 px) this way I avoid refreshing and redrawing if the updated position was to small.
This are just pointers, there might be a better option for you case ^^

Resources