I am working on a drawing app, with pen touch, on iphone and ipad. Till now , I have implemented the basic drawing and tested with digital pen and it work fine, but I have one issue, while drawing on iphone/ipad, if my fingers touch the screen before I draw with pen , the pen wont work, So what I want to achieve is that, I want to able to write with pen, even if my fingers are touching the ipad screen.
Regards Ranjit
There is no way to differentiate between a finger and a stylus, as a stylus is supposed to emulate a touch from a finger. You will either have to make it so that all touches draw (including a hand on the screen) or make it so only the first "finger" that touches the screen can draw (meaning that you must put the stylus on the screen before your hands can touch it).
@iLive is correct in mentioning those delegate methods that you should implement, but I assume that you are already using these methods.
UPDATE:
Tracking specific touches is as simple as adding the addresses of their instances to a array during touchesBegan. Append them to a CFMutableArrayRef. Then, in the touchesMoved method, you can simply get the index of the touch in order.
The most likely answer is in the number of touches you can receive.
Evidently, if do not enable multi-touch you will be stuck in receiving one touch at a time!
Thus, if your hand touched the screen first, then the other touches made by the digital pen will not be received.
First start by enabling the multi-touch
capability.
These are the methods you will have to implement:
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
Look into Apple's link: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html for more information!
Hope this helped!
Addition You could make at least a layer (accepting no touches) coming up from the lower edge (configurable in height by the user) so that at least your palm can rest on the ipad screen surface which lowers the possibility of unwanted touches and makes drawing more stable.
来源:https://stackoverflow.com/questions/11081383/writing-with-digital-pen-on-ipad-iphone-by-keeping-hand-on-screen