To teach you to draw a natural signature on iOS.

Source: Internet
Author: User
Tags connect touch

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.