Here's a great article on how to get a smooth signature on Android:smoother signatures, but I didn't find a way to write on iOS. So what exactly does it take to get the user's signature on the iOS device?
Although I didn't find any articles about getting the signatures, there was already a well implemented app on the App Store. Paper by is a painting ipad app that has beautiful and sensitive brushes, which is the user experience I want to pursue.
Code can be obtained from here:Signaturedemo
Connecting dots into lines
The easiest way to do this is to get the touch points in turn and connect them in a straight line.
Create path in the initialization method of the UIView subclass and gesture Recongnizer to capture the touch event.
Create a path to connect lines
path = [Uibezierpath Bezierpath];
Capture touches
Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:self action:@ Selector (pan:)];
pan.maximumnumberoftouches = Pan.minimumnumberoftouches = 1;
[Self addgesturerecognizer:pan];
The captured Pan event location data is added to the Bezier path in turn, and the dots are connected to a line.
-(void) pan: (Uipangesturerecognizer *) pan {
cgpoint currentpoint = [pan locationinview:self];
if (pan.state = = Uigesturerecognizerstatebegan) {
[path movetopoint:currentpoint];
} else if (pan.state = = uigesturerecognizerstatechanged)
[path addlinetopoint:currentpoint];
[Self setneedsdisplay];
}
Draw a trajectory
-(void) DrawRect: (cgrect) rect
{
[[Uicolor Blackcolor] setstroke];
[path stroke];
}
Using this method to draw a letter J exposes some problems.
When the signature speed is slow, iOS can capture enough touch position information to make the connected lines look less obvious. But when the fingers move fast, there's trouble.
Building Advanced gesture recognizers, introduced in the 2012 Apple developer Conference, says math can be used to solve the problem.