├── image
├── IMG_2048.jpg
└── IMG_2049.jpg
├── WFSignatureView
├── WFSignatureView.xcodeproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── project.pbxproj
├── WFSignatureViewTests
│ ├── Info.plist
│ └── WFSignatureViewTests.swift
├── WFSignatureViewUITests
│ ├── Info.plist
│ └── WFSignatureViewUITests.swift
└── WFSignatureView
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Info.plist
│ ├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
│ ├── AppDelegate.swift
│ ├── ViewController.swift
│ └── source
│ └── WFSignatureView.swift
├── README.md
├── WFSignatureView_OC
├── WFSignatureView.h
└── WFSignatureView.m
├── LICENSE
└── .gitignore
/image/IMG_2048.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Babywolf1992/WFSignatureView/HEAD/image/IMG_2048.jpg
--------------------------------------------------------------------------------
/image/IMG_2049.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Babywolf1992/WFSignatureView/HEAD/image/IMG_2049.jpg
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WFSignatureView(QQ:591138406)
2 | ### 简介:
3 |
4 | WFSignatureView是swift语言编写,基于OpenGL框架实现的一个手写签批框架,使用上比CGContext效果更为流畅,带有一定笔锋效果(基于真机下手写效果明显)。
5 |
6 |
7 |
8 | ### 使用:
9 |
10 | 直接将WFSignatureView作为视图调用addSubView即可,需要注意,其控制器需要继承GLKViewController。
11 |
12 |
13 |
14 | ### Screenshot
15 |
16 | 图一:
17 |
18 | 
19 |
20 | 图二:
21 |
22 | 
23 |
--------------------------------------------------------------------------------
/WFSignatureView_OC/WFSignatureView.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | @interface WFSignatureView : GLKView {
5 | NSMutableArray* pointsArray;
6 | NSMutableArray* pathsArray;
7 | NSMutableArray* colorsArray;
8 | NSMutableArray* sizesArray;
9 |
10 | }
11 |
12 | @property (assign, nonatomic) UIColor *strokeColor;
13 | @property (assign, nonatomic) BOOL hasSignature;
14 | @property (strong, nonatomic) UIImage *signatureImage;
15 | @property (nonatomic, assign) NSInteger width;
16 | @property (nonatomic, assign) int currentPath;
17 | @property (nonatomic, assign) GLKVector3 penColor;
18 |
19 | - (void)erase;
20 | - (void)remove;
21 | - (void)pan:(UIPanGestureRecognizer *)p;
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureViewTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureViewUITests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureViewTests/WFSignatureViewTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WFSignatureViewTests.swift
3 | // WFSignatureViewTests
4 | //
5 | // Created by babywolf on 17/8/30.
6 | // Copyright © 2017年 babywolf. All rights reserved.
7 | //
8 |
9 | import XCTest
10 | @testable import WFSignatureView
11 |
12 | class WFSignatureViewTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | // Use XCTAssert and related functions to verify your tests produce the correct results.
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measure {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureViewUITests/WFSignatureViewUITests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WFSignatureViewUITests.swift
3 | // WFSignatureViewUITests
4 | //
5 | // Created by babywolf on 17/8/30.
6 | // Copyright © 2017年 babywolf. All rights reserved.
7 | //
8 |
9 | import XCTest
10 |
11 | class WFSignatureViewUITests: XCTestCase {
12 |
13 | override func setUp() {
14 | super.setUp()
15 |
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 |
18 | // In UI tests it is usually best to stop immediately when a failure occurs.
19 | continueAfterFailure = false
20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
21 | XCUIApplication().launch()
22 |
23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
24 | }
25 |
26 | override func tearDown() {
27 | // Put teardown code here. This method is called after the invocation of each test method in the class.
28 | super.tearDown()
29 | }
30 |
31 | func testExample() {
32 | // Use recording to get started writing UI tests.
33 | // Use XCTAssert and related functions to verify your tests produce the correct results.
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | # CocoaPods
32 | #
33 | # We recommend against adding the Pods directory to your .gitignore. However
34 | # you should judge for yourself, the pros and cons are mentioned at:
35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36 | #
37 | # Pods/
38 |
39 | # Carthage
40 | #
41 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
42 | # Carthage/Checkouts
43 |
44 | Carthage/Build
45 |
46 | # fastlane
47 | #
48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
49 | # screenshots whenever they are needed.
50 | # For more information about the recommended setup visit:
51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
52 |
53 | fastlane/report.xml
54 | fastlane/Preview.html
55 | fastlane/screenshots
56 | fastlane/test_output
57 |
58 | # Code Injection
59 | #
60 | # After new code Injection tools there's a generated folder /iOSInjectionProject
61 | # https://github.com/johnno1962/injectionforxcode
62 |
63 | iOSInjectionProject/
64 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // WFSignatureView
4 | //
5 | // Created by babywolf on 17/8/30.
6 | // Copyright © 2017年 babywolf. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | self.window = UIWindow.init(frame: UIScreen.main.bounds);
20 | self.window?.backgroundColor = UIColor.clear;
21 |
22 | let vc = ViewController.init();
23 | self.window?.rootViewController = vc;
24 | self.window?.makeKeyAndVisible();
25 |
26 | return true
27 | }
28 |
29 | func applicationWillResignActive(_ application: UIApplication) {
30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
31 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
32 | }
33 |
34 | func applicationDidEnterBackground(_ application: UIApplication) {
35 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
37 | }
38 |
39 | func applicationWillEnterForeground(_ application: UIApplication) {
40 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
41 | }
42 |
43 | func applicationDidBecomeActive(_ application: UIApplication) {
44 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
45 | }
46 |
47 | func applicationWillTerminate(_ application: UIApplication) {
48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
49 | }
50 |
51 |
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // WFSignatureView
4 | //
5 | // Created by babywolf on 17/8/30.
6 | // Copyright © 2017年 babywolf. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import GLKit
11 |
12 | class ViewController: GLKViewController {
13 |
14 | override func viewDidLoad() {
15 | super.viewDidLoad()
16 | // Do any additional setup after loading the view, typically from a nib.
17 | let context = EAGLContext.init(api: EAGLRenderingAPI.openGLES1);
18 | let view = WFSignatureView.init(frame: self.view.bounds, context: context!);
19 | view.tag = 1000;
20 | view.isOpaque = false;
21 | self.view .addSubview(view);
22 |
23 | let space : CGFloat = 30;
24 | let width = (self.view.frame.width-space*5) / 4;
25 |
26 | let btnView = UIView.init(frame: CGRect.init(x: 0, y: self.view.frame.size.height-30, width: self.view.frame.width, height: 25));
27 | self.view.addSubview(btnView);
28 |
29 | for i in 0...3 {
30 | let btn = UIButton.init(frame: CGRect.init(x: CGFloat(space+(space+width)*CGFloat(i)), y: 0, width: width, height: 25));
31 | btn.tag = i+100;
32 | btn.addTarget(self, action: #selector(self.btnAction(sender:)), for: UIControlEvents.touchUpInside);
33 | switch i {
34 | case 0:
35 | btn.backgroundColor=UIColor.black;
36 | case 1:
37 | btn.backgroundColor=UIColor.red;
38 | case 2:
39 | btn.backgroundColor=UIColor.green;
40 | case 3:
41 | btn.backgroundColor=UIColor.blue;
42 | default:
43 | btn.backgroundColor=UIColor.black;
44 | }
45 | btnView.addSubview(btn);
46 | }
47 |
48 | let removeBtn = UIButton.init(frame: CGRect.init(x: self.view.frame.size.width-80, y: 40, width: 60, height: 20));
49 | self.view.addSubview(removeBtn);
50 | removeBtn.setTitle("retraction", for: UIControlState.normal)
51 | removeBtn.setTitle("retraction", for: UIControlState.highlighted)
52 | removeBtn.setTitleColor(UIColor.black, for: UIControlState.normal)
53 | removeBtn.setTitleColor(UIColor.black, for: UIControlState.highlighted)
54 | removeBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
55 | removeBtn.addTarget(self, action: #selector(self.retractionAction(sender:)), for: UIControlEvents.touchUpInside)
56 | }
57 |
58 | func btnAction(sender : UIButton) {
59 | let view : WFSignatureView = self.view.viewWithTag(1000) as! WFSignatureView;
60 | switch sender.tag {
61 | case 100:
62 | view.setPenColor(color: UIColor.black);
63 | case 101:
64 | view.setPenColor(color: UIColor.red);
65 | case 102:
66 | view.setPenColor(color: UIColor.green);
67 | case 103:
68 | view.setPenColor(color: UIColor.blue);
69 | default:
70 | view.setPenColor(color: UIColor.black);
71 | }
72 | }
73 |
74 | func retractionAction(sender : UIButton) {
75 | let view : WFSignatureView = self.view.viewWithTag(1000) as! WFSignatureView;
76 | view.remove();
77 | }
78 |
79 | override func didReceiveMemoryWarning() {
80 | super.didReceiveMemoryWarning()
81 | // Dispose of any resources that can be recreated.
82 | }
83 |
84 |
85 | }
86 |
87 |
--------------------------------------------------------------------------------
/WFSignatureView_OC/WFSignatureView.m:
--------------------------------------------------------------------------------
1 | #import "WFSignatureView.h"
2 | #import
3 |
4 | #define STROKE_WIDTH_MIN 0.001
5 | #define STROKE_WIDTH_MAX 0.02
6 | #define STROKE_WIDTH_SMOOTHING 0.2
7 |
8 | #define VELOCITY_CLAMP_MIN 20
9 | #define VELOCITY_CLAMP_MAX 5000
10 |
11 | #define QUADRATIC_DISTANCE_TOLERANCE 5.0
12 |
13 | #define MAXIMUM_VERTECES 100000
14 |
15 | static GLKVector3 StrokeColor = { 0, 0, 0 };
16 | static float clearColor[4] = { 1, 1, 1, 0 };
17 |
18 | struct WFSignaturePoint
19 | {
20 | GLKVector3 vertex;
21 | GLKVector3 color;
22 | };
23 | typedef struct WFSignaturePoint WFSignaturePoint;
24 |
25 |
26 | static const int maxLength = MAXIMUM_VERTECES;
27 |
28 |
29 | static inline void addVertex(uint *length, NSMutableArray *pointsArray, WFSignaturePoint v) {
30 | uint sum = 0;
31 | for (NSNumber *num in pointsArray) {
32 | sum += (NSUInteger)[num integerValue];
33 | }
34 | uint len = *length + sum;
35 | if (len >= maxLength) {
36 | return;
37 | }
38 |
39 | GLvoid *data = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
40 | memcpy(data + sizeof(WFSignaturePoint) * len, &v, sizeof(WFSignaturePoint));
41 | glUnmapBufferOES(GL_ARRAY_BUFFER);
42 | // NSLog(@"%u",len);
43 | (*length)++;
44 | }
45 |
46 | static inline CGPoint QuadraticPointInCurve(CGPoint start, CGPoint end, CGPoint controlPoint, float percent) {
47 | double a = pow((1.0 - percent), 2.0);
48 | double b = 2.0 * percent * (1.0 - percent);
49 | double c = pow(percent, 2.0);
50 |
51 | return (CGPoint) {
52 | a * start.x + b * controlPoint.x + c * end.x,
53 | a * start.y + b * controlPoint.y + c * end.y
54 | };
55 | }
56 |
57 | static float generateRandom(float from, float to) { return random() % 10000 / 10000.0 * (to - from) + from; }
58 | static float clamp(float min, float max, float value) { return fmaxf(min, fminf(max, value)); }
59 |
60 | static GLKVector3 perpendicular(WFSignaturePoint p1, WFSignaturePoint p2) {
61 | GLKVector3 ret;
62 | ret.x = p2.vertex.y - p1.vertex.y;
63 | ret.y = -1 * (p2.vertex.x - p1.vertex.x);
64 | ret.z = 0;
65 | return ret;
66 | }
67 |
68 | static WFSignaturePoint ViewPointToGL(CGPoint viewPoint, CGRect bounds, GLKVector3 color) {
69 |
70 | return (WFSignaturePoint) {
71 | {
72 | (viewPoint.x / bounds.size.width * 2.0 - 1),
73 | ((viewPoint.y / bounds.size.height) * 2.0 - 1) * -1,
74 | 0
75 | },
76 | color
77 | };
78 | }
79 |
80 |
81 | @interface WFSignatureView () {
82 | // OpenGL state
83 | EAGLContext *context;
84 | GLKBaseEffect *effect;
85 |
86 | GLuint vertexArray;
87 | GLuint vertexBuffer;
88 | GLuint dotsArray;
89 | GLuint dotsBuffer;
90 |
91 | GLvoid *data;
92 |
93 | // Array of verteces, with current length
94 | WFSignaturePoint SignatureVertexData[maxLength];
95 | uint length;
96 |
97 | WFSignaturePoint SignatureDotsData[maxLength];
98 | uint dotsLength;
99 |
100 |
101 | float penThickness;
102 | float previousThickness;
103 |
104 |
105 | CGPoint previousPoint;
106 | CGPoint previousMidPoint;
107 | WFSignaturePoint previousVertex;
108 | WFSignaturePoint currentVelocity;
109 | }
110 |
111 | @end
112 |
113 |
114 | @implementation WFSignatureView
115 |
116 | - (void)commonInit {
117 | context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
118 | GLKVector3 color = { 0, 0, 0 };
119 | self.penColor = color;
120 |
121 | if (context) {
122 | time(NULL);
123 | _currentPath = 0;
124 | pointsArray = [[NSMutableArray alloc] initWithCapacity:10];
125 | pathsArray = [[NSMutableArray alloc] initWithCapacity:10];
126 | sizesArray = [[NSMutableArray alloc] initWithCapacity:10];
127 | colorsArray = [[NSMutableArray alloc] initWithCapacity:10];
128 |
129 | self.backgroundColor = [UIColor whiteColor];
130 | self.opaque = NO;
131 |
132 | self.context = context;
133 | self.drawableDepthFormat = GLKViewDrawableDepthFormat24;
134 | self.enableSetNeedsDisplay = YES;
135 |
136 | // Turn on antialiasing
137 | self.drawableMultisample = GLKViewDrawableMultisample4X;
138 |
139 | [self setupGL];
140 |
141 | // Capture touches
142 | UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
143 | pan.maximumNumberOfTouches = pan.minimumNumberOfTouches = 1;
144 | pan.cancelsTouchesInView = YES;
145 | [self addGestureRecognizer:pan];
146 |
147 | } else [NSException raise:@"NSOpenGLES2ContextException" format:@"Failed to create OpenGL ES2 context"];
148 | }
149 |
150 |
151 | - (id)initWithCoder:(NSCoder *)aDecoder
152 | {
153 | if (self = [super initWithCoder:aDecoder]) [self commonInit];
154 | return self;
155 | }
156 |
157 |
158 | - (id)initWithFrame:(CGRect)frame context:(EAGLContext *)ctx
159 | {
160 | if (self = [super initWithFrame:frame context:ctx]) [self commonInit];
161 | return self;
162 | }
163 |
164 | - (id)initWithFrame:(CGRect)frame {
165 | if (self = [super initWithFrame:frame]) {
166 | [self commonInit];
167 | }
168 | return self;
169 | }
170 |
171 | - (void)dealloc
172 | {
173 | [self tearDownGL];
174 |
175 | if ([EAGLContext currentContext] == context) {
176 | [EAGLContext setCurrentContext:nil];
177 | }
178 | context = nil;
179 | }
180 |
181 |
182 | - (void)drawRect:(CGRect)rect
183 | {
184 | glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
185 | glClear(GL_COLOR_BUFFER_BIT);
186 |
187 | [effect prepareToDraw];
188 |
189 | // Drawing of signature lines
190 | uint len = 0;
191 | for (NSNumber *num in pointsArray) {
192 | len += [num integerValue];
193 | }
194 | len += length;
195 | if (len > 2) {
196 | glBindVertexArrayOES(vertexArray);
197 | glDrawArrays(GL_TRIANGLE_STRIP, 0, len);
198 | }
199 |
200 | if (dotsLength > 0) {
201 | glBindVertexArrayOES(dotsArray);
202 | glDrawArrays(GL_TRIANGLE_STRIP, 0, dotsLength);
203 | }
204 | }
205 |
206 | - (void)erase {
207 | length = 0;
208 | dotsLength = 0;
209 | [pointsArray removeAllObjects];
210 | self.hasSignature = NO;
211 |
212 | [self setNeedsDisplay];
213 | }
214 |
215 | - (void)remove {
216 | [pointsArray removeLastObject];
217 | self.hasSignature = NO;
218 | [self setNeedsDisplay];
219 | }
220 |
221 | - (UIImage *)signatureImage
222 | {
223 | if (!self.hasSignature)
224 | return nil;
225 |
226 | UIImage *screenshot = [self snapshot];
227 |
228 | return screenshot;
229 | }
230 |
231 |
232 | #pragma mark - Gesture Recognizers
233 |
234 |
235 | - (void)tap:(UITapGestureRecognizer *)t {
236 | CGPoint l = [t locationInView:self];
237 |
238 | if (t.state == UIGestureRecognizerStateRecognized) {
239 | glBindBuffer(GL_ARRAY_BUFFER, dotsBuffer);
240 |
241 | WFSignaturePoint touchPoint = ViewPointToGL(l, self.bounds, self.penColor);
242 | addVertex(&dotsLength, pointsArray, touchPoint);
243 |
244 | WFSignaturePoint centerPoint = touchPoint;
245 | centerPoint.color = StrokeColor;
246 | addVertex(&dotsLength, pointsArray, centerPoint);
247 |
248 | static int segments = 20;
249 | GLKVector2 radius = (GLKVector2){
250 | clamp(0.00001, 0.02, penThickness * generateRandom(0.5, 1.5)),
251 | clamp(0.00001, 0.02, penThickness * generateRandom(0.5, 1.5))
252 | };
253 | GLKVector2 velocityRadius = radius;
254 | float angle = 0;
255 |
256 | for (int i = 0; i <= segments; i++) {
257 |
258 | WFSignaturePoint p = centerPoint;
259 | p.vertex.x += velocityRadius.x * cosf(angle);
260 | p.vertex.y += velocityRadius.y * sinf(angle);
261 |
262 | addVertex(&dotsLength, pointsArray, p);
263 | addVertex(&dotsLength, pointsArray, centerPoint);
264 |
265 | angle += M_PI * 2.0 / segments;
266 | }
267 |
268 | addVertex(&dotsLength, pointsArray, touchPoint);
269 |
270 | glBindBuffer(GL_ARRAY_BUFFER, 0);
271 | }
272 |
273 | [self setNeedsDisplay];
274 | }
275 |
276 |
277 | - (void)longPress:(UILongPressGestureRecognizer *)lp {
278 | [self erase];
279 | }
280 |
281 | - (void)pan:(UIPanGestureRecognizer *)p {
282 |
283 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
284 |
285 | CGPoint v = [p velocityInView:self];
286 | CGPoint l = [p locationInView:self];
287 |
288 | currentVelocity = ViewPointToGL(v, self.bounds, (GLKVector3){0,0,0});
289 | float distance = 0.;
290 | if (previousPoint.x > 0) {
291 | distance = sqrtf((l.x - previousPoint.x) * (l.x - previousPoint.x) + (l.y - previousPoint.y) * (l.y - previousPoint.y));
292 | }
293 |
294 | float width_max = STROKE_WIDTH_MAX + self.width*0.015;
295 | float width_min = STROKE_WIDTH_MIN + self.width*0.001;
296 |
297 | float velocityMagnitude = sqrtf(v.x*v.x + v.y*v.y);
298 | float clampedVelocityMagnitude = clamp(VELOCITY_CLAMP_MIN, VELOCITY_CLAMP_MAX, velocityMagnitude);
299 | float normalizedVelocity = (clampedVelocityMagnitude - VELOCITY_CLAMP_MIN) / (VELOCITY_CLAMP_MAX - VELOCITY_CLAMP_MIN);
300 |
301 | float lowPassFilterAlpha = STROKE_WIDTH_SMOOTHING;
302 | float newThickness = (width_max - width_min) * (1 - normalizedVelocity) + width_min;
303 | penThickness = penThickness * lowPassFilterAlpha + newThickness * (1 - lowPassFilterAlpha);
304 |
305 | if ([p state] == UIGestureRecognizerStateBegan) {
306 |
307 | previousPoint = l;
308 | previousMidPoint = l;
309 |
310 | WFSignaturePoint startPoint = ViewPointToGL(l, self.bounds, self.penColor);
311 | previousVertex = startPoint;
312 | previousThickness = penThickness;
313 |
314 |
315 | addVertex(&length, pointsArray, startPoint);
316 | addVertex(&length, pointsArray, previousVertex);
317 |
318 | self.hasSignature = YES;
319 | // NSLog(@"%d",pointsArray.count);
320 | self.currentPath = (int)pointsArray.count;
321 |
322 | } else if ([p state] == UIGestureRecognizerStateChanged) {
323 |
324 | CGPoint mid = CGPointMake((l.x + previousPoint.x) / 2.0, (l.y + previousPoint.y) / 2.0);
325 |
326 | if (distance > QUADRATIC_DISTANCE_TOLERANCE) {
327 | // Plot quadratic bezier instead of line
328 | unsigned int i;
329 |
330 | int segments = (int) distance / 1.5;
331 |
332 | float startPenThickness = previousThickness;
333 | float endPenThickness = penThickness;
334 | previousThickness = penThickness;
335 |
336 | for (i = 0; i < segments; i++)
337 | {
338 | penThickness = startPenThickness + ((endPenThickness - startPenThickness) / segments) * i;
339 |
340 | CGPoint quadPoint = QuadraticPointInCurve(previousMidPoint, mid, previousPoint, (float)i / (float)(segments));
341 |
342 | WFSignaturePoint v = ViewPointToGL(quadPoint, self.bounds, self.penColor);
343 | [self addTriangleStripPointsForPrevious:previousVertex next:v];
344 |
345 | previousVertex = v;
346 | }
347 | } else if (distance > 1.0) {
348 |
349 | WFSignaturePoint v = ViewPointToGL(l, self.bounds, self.penColor);
350 | [self addTriangleStripPointsForPrevious:previousVertex next:v];
351 |
352 | previousVertex = v;
353 | previousThickness = penThickness;
354 | }
355 |
356 | previousPoint = l;
357 | previousMidPoint = mid;
358 |
359 | } else if (p.state == UIGestureRecognizerStateEnded | p.state == UIGestureRecognizerStateCancelled) {
360 |
361 | WFSignaturePoint v = ViewPointToGL(l, self.bounds, self.penColor);
362 | addVertex(&length, pointsArray, v);
363 |
364 | previousVertex = v;
365 | addVertex(&length, pointsArray, previousVertex);
366 | [pointsArray addObject:[NSNumber numberWithInt:length]];
367 | length = 0;
368 | }
369 |
370 | [self setNeedsDisplay];
371 | }
372 |
373 |
374 | - (void)setStrokeColor:(UIColor *)strokeColor {
375 | _strokeColor = strokeColor;
376 | [self updateStrokeColor];
377 | }
378 |
379 |
380 | #pragma mark - Private
381 |
382 | - (void)updateStrokeColor {
383 | CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0, white = 0.0;
384 | if (effect && self.strokeColor && [self.strokeColor getRed:&red green:&green blue:&blue alpha:&alpha]) {
385 | effect.constantColor = GLKVector4Make(red, green, blue, alpha);
386 | } else if (effect && self.strokeColor && [self.strokeColor getWhite:&white alpha:&alpha]) {
387 | effect.constantColor = GLKVector4Make(white, white, white, alpha);
388 | } else effect.constantColor = GLKVector4Make(0,0,0,1);
389 | }
390 |
391 |
392 | - (void)setBackgroundColor:(UIColor *)backgroundColor {
393 | [super setBackgroundColor:backgroundColor];
394 |
395 | CGFloat red, green, blue, alpha, white;
396 | if ([backgroundColor getRed:&red green:&green blue:&blue alpha:&alpha]) {
397 | clearColor[0] = red;
398 | clearColor[1] = green;
399 | clearColor[2] = blue;
400 | } else if ([backgroundColor getWhite:&white alpha:&alpha]) {
401 | clearColor[0] = white;
402 | clearColor[1] = white;
403 | clearColor[2] = white;
404 | }
405 | }
406 |
407 | - (void)bindShaderAttributes {
408 | glEnableVertexAttribArray(GLKVertexAttribPosition);
409 | glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(WFSignaturePoint), 0);
410 | glEnableVertexAttribArray(GLKVertexAttribColor);
411 | glVertexAttribPointer(GLKVertexAttribColor, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (char *)12);
412 | }
413 |
414 | - (void)setupGL
415 | {
416 | [EAGLContext setCurrentContext:context];
417 |
418 | effect = [[GLKBaseEffect alloc] init];
419 |
420 | [self updateStrokeColor];
421 |
422 |
423 | glDisable(GL_DEPTH_TEST);
424 |
425 | // Signature Lines
426 | glGenVertexArraysOES(1, &vertexArray);
427 | glBindVertexArrayOES(vertexArray);
428 |
429 | glGenBuffers(1, &vertexBuffer);
430 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
431 | glBufferData(GL_ARRAY_BUFFER, sizeof(SignatureVertexData), SignatureVertexData, GL_DYNAMIC_DRAW);
432 | [self bindShaderAttributes];
433 |
434 |
435 | // Signature Dots
436 | glGenVertexArraysOES(1, &dotsArray);
437 | glBindVertexArrayOES(dotsArray);
438 |
439 | glGenBuffers(1, &dotsBuffer);
440 | glBindBuffer(GL_ARRAY_BUFFER, dotsBuffer);
441 | glBufferData(GL_ARRAY_BUFFER, sizeof(SignatureDotsData), SignatureDotsData, GL_DYNAMIC_DRAW);
442 | [self bindShaderAttributes];
443 |
444 |
445 | glBindVertexArrayOES(0);
446 |
447 |
448 | // Perspective
449 | GLKMatrix4 ortho = GLKMatrix4MakeOrtho(-1, 1, -1, 1, 0.1f, 2.0f);
450 | effect.transform.projectionMatrix = ortho;
451 |
452 | GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.0f);
453 | effect.transform.modelviewMatrix = modelViewMatrix;
454 |
455 | length = 0;
456 | penThickness = 0.003;
457 | if (penThickness<0.003 || penThickness>0.008) {
458 | penThickness = 0.003;
459 | }
460 | self.width = 1;
461 | previousPoint = CGPointMake(-100, -100);
462 | }
463 |
464 |
465 |
466 | - (void)addTriangleStripPointsForPrevious:(WFSignaturePoint)previous next:(WFSignaturePoint)next {
467 | float toTravel = penThickness / 2.0;
468 |
469 | for (int i = 0; i < 2; i++) {
470 | GLKVector3 p = perpendicular(previous, next);
471 | GLKVector3 p1 = next.vertex;
472 | GLKVector3 ref = GLKVector3Add(p1, p);
473 |
474 | float distance = GLKVector3Distance(p1, ref);
475 | float difX = p1.x - ref.x;
476 | float difY = p1.y - ref.y;
477 | float ratio = -1.0 * (toTravel / distance);
478 |
479 | difX = difX * ratio;
480 | difY = difY * ratio;
481 |
482 | WFSignaturePoint stripPoint = {
483 | { p1.x + difX, p1.y + difY, 0.0 },
484 | self.penColor
485 | };
486 | addVertex(&length, pointsArray, stripPoint);
487 |
488 | toTravel *= -1;
489 | }
490 | }
491 |
492 |
493 | - (void)tearDownGL
494 | {
495 | [EAGLContext setCurrentContext:context];
496 |
497 | glDeleteVertexArraysOES(1, &vertexArray);
498 | glDeleteBuffers(1, &vertexBuffer);
499 |
500 | glDeleteVertexArraysOES(1, &dotsArray);
501 | glDeleteBuffers(1, &dotsBuffer);
502 |
503 | effect = nil;
504 | }
505 |
506 | @end
507 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView/source/WFSignatureView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // WFSignatureView.swift
3 | // WFSignatureView
4 | //
5 | // Created by babywolf on 17/8/30.
6 | // Copyright © 2017年 babywolf. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import GLKit
11 | import OpenGLES.ES2.glext
12 |
13 | let STROKE_WIDTH_MIN = 0.004 // Stroke width determined by touch velocity
14 | let STROKE_WIDTH_MAX = 0.030
15 | let STROKE_WIDTH_SMOOTHING = 0.5 // Low pass filter alpha
16 |
17 | let VELOCITY_CLAMP_MIN = 20
18 | let VELOCITY_CLAMP_MAX = 5000
19 |
20 | let QUADRATIC_DISTANCE_TOLERANCE = 3.0 // Minimum distance to make a curve
21 |
22 | let MAXIMUM_VERTECES = 100000
23 |
24 | let StrokeColor : GLKVector3 = GLKVector3.init(v: (0, 0, 0))
25 | var clearColor : Array = [1.0,1.0,1.0,0.0]
26 |
27 | public struct _WFSignaturePoint {
28 | public var vertex : GLKVector3
29 | public var color : GLKVector3
30 | }
31 | public typealias WFSignaturePoint = _WFSignaturePoint
32 |
33 | let maxLength = MAXIMUM_VERTECES
34 |
35 | func addVertex( length : inout uint, pointsArray : Array, v : UnsafeRawPointer) {
36 | var sum = 0;
37 | for num : NSNumber in pointsArray {
38 | sum += num.intValue;
39 | }
40 | let len = Int(length) + sum;
41 | if len >= maxLength {
42 | return;
43 | }
44 | var data : UnsafeMutableRawPointer
45 | data = glMapBufferOES(UInt32(GL_ARRAY_BUFFER), UInt32(GL_WRITE_ONLY_OES))
46 | data = data + MemoryLayout.size * len
47 | memcpy(data, v, MemoryLayout.size)
48 | glUnmapBufferOES(GLenum(GL_ARRAY_BUFFER));
49 | length += 1
50 | }
51 |
52 | func QuadraticPointInCurve( start : CGPoint, end : CGPoint, controlPoint : CGPoint, percent : Float) -> CGPoint {
53 | var a, b, c : Float
54 | a = pow((1.0-percent), 2.0);
55 | b = 2.0 * percent * (1.0 - percent);
56 | c = pow(percent, 2.0);
57 |
58 | return CGPoint.init(x: Double(a) * Double(start.x) + Double(b) * Double(controlPoint.x) + Double(c) * Double(end.x), y: Double(a) * Double(start.y) + Double(b) * Double(controlPoint.y) + Double(c) * Double(end.y));
59 | }
60 |
61 | func generateRandom(from : Float, to : Float) -> Float {
62 | return Float(arc4random() % 10000) / 10000.0 * (to - from) + from;
63 | }
64 |
65 | func clamp(min : Float, max : Float, value : Float) -> Float {
66 | return fmaxf(min, fminf(max, value));
67 | }
68 |
69 | func perpendicular(p1 : WFSignaturePoint, p2 : WFSignaturePoint) -> GLKVector3 {
70 | let ret = GLKVector3.init(v: (p2.vertex.y - p1.vertex.y, -1 * (p2.vertex.x - p1.vertex.x), 0))
71 | return ret;
72 | }
73 |
74 | func viewPointToGL(viewPoint : CGPoint, bounds : CGRect, color : GLKVector3) -> WFSignaturePoint {
75 | return WFSignaturePoint.init(vertex: GLKVector3.init(v: (Float(viewPoint.x / bounds.size.width * 2.0) - 1, (Float((viewPoint.y / bounds.size.height) * 2.0) - 1) * -1, 0)), color: color);
76 | }
77 |
78 | class WFSignatureView: GLKView {
79 | var strokeColor : UIColor?;
80 |
81 | var hasSignature : Bool;
82 |
83 | var signatureImage : UIImage? {
84 | get {
85 | return self.snapshot;
86 | }
87 | }
88 |
89 | // OpenGL state
90 | var glContext : EAGLContext?
91 | var effect : GLKBaseEffect?
92 |
93 | var vertexArray : GLuint = 0
94 | var vertexBuffer : GLuint = 0
95 | var dotsArray : GLuint = 0
96 | var dotsBuffer : GLuint = 0
97 |
98 | var signatureVertexData : Array = Array.init(repeating: nil, count: maxLength)
99 | var length : uint = 0
100 |
101 | var signatureDotsData : Array = Array.init(repeating: nil, count: maxLength)
102 | var dotsLength : uint = 0
103 |
104 | var penThickness : Float = 0.0;
105 | var previousThickness : Float = 0.0;
106 |
107 | var previousPoint : CGPoint?
108 | var previousMidPoint : CGPoint?
109 | var previousVertex : WFSignaturePoint?
110 | var currentVelocity : WFSignaturePoint?
111 |
112 | private var pointsArray : Array = Array.init();
113 | private var penColor : GLKVector3 = GLKVector3.init(v: (0, 0, 0))
114 | private var currentPath : Int = 0;
115 |
116 | required init?(coder aDecoder: NSCoder) {
117 | self.hasSignature = true;
118 | super.init(coder: aDecoder);
119 | self.commonInit();
120 | }
121 |
122 | override init(frame: CGRect, context: EAGLContext) {
123 | self.hasSignature = true;
124 | super.init(frame: frame, context: context);
125 | self.commonInit();
126 | }
127 |
128 | func commonInit() {
129 | glContext = EAGLContext.init(api: EAGLRenderingAPI(rawValue: 2)!)
130 | if glContext != nil {
131 | time(UnsafeMutablePointer.init(bitPattern: 0));
132 |
133 | self.backgroundColor = UIColor.white;
134 | self.setBackgroundColor(backgroundColor: UIColor.white);
135 | self.isOpaque = false;
136 |
137 | self.context = glContext!;
138 | self.drawableDepthFormat = GLKViewDrawableDepthFormat.init(rawValue: 2)!;
139 | self.enableSetNeedsDisplay = true;
140 |
141 | self.drawableMultisample = GLKViewDrawableMultisample.init(rawValue: 1)!;
142 |
143 | self.setupGL();
144 |
145 | let pan = UIPanGestureRecognizer.init(target: self, action: #selector(self.pan(p:)));
146 | pan.maximumNumberOfTouches = 1;
147 | pan.minimumNumberOfTouches = 1;
148 | pan.cancelsTouchesInView = true;
149 | self.addGestureRecognizer(pan);
150 |
151 | let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.tap(t:)));
152 | tap.cancelsTouchesInView = true;
153 | self.addGestureRecognizer(tap);
154 |
155 | let longer = UILongPressGestureRecognizer.init(target: self, action: #selector(self.longPress(p:)));
156 | longer.cancelsTouchesInView = true;
157 | self.addGestureRecognizer(longer);
158 | }else {
159 | print("NSOpenGLES2ContextException");
160 | }
161 | }
162 |
163 | deinit {
164 | self.tearDownGL();
165 |
166 | if EAGLContext.current() == glContext {
167 | EAGLContext.setCurrent(nil);
168 | }
169 | glContext = nil;
170 | }
171 |
172 | override func draw(_ rect: CGRect) {
173 | glClearColor(GLfloat(clearColor[0]), GLfloat(clearColor[1]), GLfloat(clearColor[2]), GLfloat(clearColor[3]))
174 | glClear(GLbitfield(GL_COLOR_BUFFER_BIT));
175 |
176 | effect?.prepareToDraw();
177 |
178 | var len = 0;
179 | for num in pointsArray {
180 | len += num.intValue;
181 | }
182 | len += Int(length);
183 |
184 | if len > 2 {
185 | glBindVertexArrayOES(vertexArray);
186 | glDrawArrays(GLenum(GL_TRIANGLE_STRIP), 0, GLsizei(len));
187 | }
188 |
189 | if dotsLength > 0 {
190 | glBindVertexArrayOES(dotsArray);
191 | glDrawArrays(GLenum(GL_TRIANGLE_STRIP), 0, GLsizei(dotsLength));
192 | }
193 | }
194 |
195 | func erase() {
196 | length = 0;
197 | dotsLength = 0;
198 | pointsArray.removeAll();
199 | self.hasSignature = false;
200 |
201 | self.setNeedsDisplay();
202 | }
203 |
204 | static var segments : Int = 20;
205 | func tap(t : UITapGestureRecognizer) {
206 | let l = t.location(in: self);
207 |
208 | if t.state == UIGestureRecognizerState.recognized {
209 | glBindBuffer(GLenum(GL_ARRAY_BUFFER), dotsBuffer);
210 |
211 | var touchPoint : WFSignaturePoint = viewPointToGL(viewPoint: l, bounds: self.bounds, color: self.penColor);
212 | addVertex(length: &dotsLength, pointsArray: pointsArray, v: &touchPoint);
213 |
214 | var centerPoint = touchPoint;
215 | centerPoint.color = StrokeColor;
216 | addVertex(length: &dotsLength, pointsArray: pointsArray, v: ¢erPoint);
217 |
218 | let radius = GLKVector2.init(v: (clamp(min: 0.00001, max: 0.02, value: penThickness * generateRandom(from: 0.5, to: 1.5)), clamp(min: 0.00001, max: 0.02, value: penThickness * generateRandom(from: 0.5, to: 1.5))));
219 | let velocityRadius = radius;
220 | var angle : Float = 0.0;
221 |
222 | for _ in 0 ... WFSignatureView.segments {
223 | let p = centerPoint;
224 | let x = p.vertex.x + velocityRadius.x * cosf(angle);
225 | let y = p.vertex.y + velocityRadius.y * sinf(angle);
226 | var point : WFSignaturePoint = WFSignaturePoint.init(vertex: GLKVector3.init(v: (x, y, p.vertex.z)), color: p.color);
227 | addVertex(length: &dotsLength, pointsArray: pointsArray, v: &point);
228 | addVertex(length: &dotsLength, pointsArray: pointsArray, v: ¢erPoint);
229 |
230 | angle += Float(M_PI * 2.0 / Double(WFSignatureView.segments));
231 | }
232 |
233 | addVertex(length: &dotsLength, pointsArray: pointsArray, v: &touchPoint);
234 | glBindBuffer(GLenum(GL_ARRAY_BUFFER), 0);
235 | }
236 | self.setNeedsDisplay();
237 | }
238 |
239 | func longPress(p : UILongPressGestureRecognizer) {
240 | self.erase();
241 | }
242 |
243 | func pan(p : UIPanGestureRecognizer) {
244 | glBindBuffer(GLenum(GL_ARRAY_BUFFER), vertexBuffer);
245 |
246 | let v : CGPoint = p.velocity(in: self);
247 | let l : CGPoint = p.location(in: self);
248 |
249 | currentVelocity = viewPointToGL(viewPoint: v, bounds: self.bounds, color: GLKVector3.init(v: (0, 0, 0)));
250 |
251 | var distance : Float = 0.0
252 | if previousPoint!.x > 0 {
253 | let a1 = (l.x - previousPoint!.x) * (l.x - previousPoint!.x);
254 | let a = a1 + (l.y - previousPoint!.y) * (l.y - previousPoint!.y);
255 | distance = sqrtf(Float(a));
256 | }
257 |
258 | let velocityMagnitude = sqrtf(Float(v.x * v.x + v.y * v.y));
259 | let clampedVelocityMagnitude = clamp(min: Float(VELOCITY_CLAMP_MIN), max: Float(VELOCITY_CLAMP_MAX), value: velocityMagnitude);
260 | let normalizedVelocity = (clampedVelocityMagnitude - Float(VELOCITY_CLAMP_MIN)) / Float(VELOCITY_CLAMP_MAX - VELOCITY_CLAMP_MIN);
261 |
262 | let lowPassFilterAlpha = STROKE_WIDTH_SMOOTHING;
263 | let newThickness = Float(STROKE_WIDTH_MAX - STROKE_WIDTH_MIN) * Float(1 - normalizedVelocity) + Float(STROKE_WIDTH_MIN);
264 | penThickness = penThickness * Float(lowPassFilterAlpha) + newThickness * Float(1 - lowPassFilterAlpha);
265 | if p.state == UIGestureRecognizerState.began {
266 | previousPoint = l;
267 | previousMidPoint = l;
268 |
269 | var startPoint = viewPointToGL(viewPoint: l, bounds: self.bounds, color: self.penColor);
270 | previousVertex = startPoint;
271 | previousThickness = penThickness;
272 |
273 | addVertex(length: &length, pointsArray: pointsArray, v: &startPoint);
274 | addVertex(length: &length, pointsArray: pointsArray, v: &previousVertex!);
275 |
276 | self.hasSignature = true;
277 | self.currentPath = pointsArray.count;
278 | }else if p.state == UIGestureRecognizerState.changed {
279 | let mid = CGPoint.init(x: (l.x + (previousPoint?.x)!) / 2.0, y: (l.y + (previousPoint?.y)!) / 2.0);
280 | if distance > Float(QUADRATIC_DISTANCE_TOLERANCE) {
281 | let segmts : Int = Int(distance/1.5);
282 | let startPenThickness = previousThickness;
283 | let endPenThickness = penThickness;
284 | previousThickness = penThickness;
285 |
286 | for index in 0 ... (segmts-1) {
287 | penThickness = startPenThickness + ((endPenThickness - startPenThickness) / Float(segmts)) * Float(index);
288 | let quadPoint = QuadraticPointInCurve(start: previousMidPoint!, end: mid, controlPoint: previousPoint!, percent: Float(index)/Float(segmts));
289 | let wfv = viewPointToGL(viewPoint: quadPoint, bounds: self.bounds, color: self.penColor);
290 | self.addTriangleStripPointsForPrevious(previous: previousVertex!, next: wfv)
291 | previousVertex = wfv;
292 | }
293 | } else if distance > 1.0 {
294 | let wfv = viewPointToGL(viewPoint: l, bounds: self.bounds, color: self.penColor);
295 | self.addTriangleStripPointsForPrevious(previous: previousVertex!, next: wfv);
296 | previousVertex = wfv;
297 | previousThickness = penThickness;
298 | }
299 | previousPoint = l;
300 | previousMidPoint = mid;
301 | } else if p.state == UIGestureRecognizerState.ended || p.state == UIGestureRecognizerState.cancelled {
302 | var wfv = viewPointToGL(viewPoint: l, bounds: self.bounds, color: self.penColor);
303 | addVertex(length: &length, pointsArray: pointsArray, v: &wfv);
304 | previousVertex = wfv;
305 | addVertex(length: &length, pointsArray: pointsArray, v: &previousVertex!);
306 | pointsArray.append(NSNumber.init(value: Int(length)))
307 | length = 0;
308 | }
309 | self.setNeedsDisplay();
310 | }
311 |
312 | func updateStrokeColor() {
313 | var red : CGFloat = 0, green : CGFloat = 0, blue : CGFloat = 0, alpha : CGFloat = 0, white : CGFloat = 1;
314 | if (effect != nil) && (self.strokeColor != nil) && self.strokeColor!.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
315 | effect?.constantColor = GLKVector4.init(v: (Float(red), Float(green), Float(blue), Float(alpha)));
316 | }else if effect != nil && self.strokeColor != nil && self.strokeColor!.getWhite(&white, alpha: &alpha) {
317 | effect?.constantColor = GLKVector4.init(v: (Float(white), Float(white), Float(white), Float(alpha)));
318 | }else {
319 | effect?.constantColor = GLKVector4.init(v: (0, 0, 0, 1));
320 | }
321 | }
322 |
323 | func setBackgroundColor(backgroundColor : UIColor) {
324 | self.backgroundColor = backgroundColor;
325 |
326 | var red : CGFloat = 0, green : CGFloat = 0, blue : CGFloat = 0, alpha : CGFloat = 0, white : CGFloat = 1;
327 | if backgroundColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
328 | clearColor[0] = red;
329 | clearColor[1] = green;
330 | clearColor[2] = blue;
331 | }else if backgroundColor.getWhite(&white, alpha: &alpha) {
332 | clearColor[0] = white;
333 | clearColor[1] = white;
334 | clearColor[2] = white;
335 | }
336 | }
337 |
338 | func bindShaderAttributes() {
339 | glEnableVertexAttribArray(GLuint(GLKVertexAttrib.position.rawValue));
340 | glVertexAttribPointer(GLuint(GLKVertexAttrib.position.rawValue), 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(MemoryLayout.size), UnsafeRawPointer.init(bitPattern: 0));
341 | glEnableVertexAttribArray(GLuint(GLKVertexAttrib.color.rawValue));
342 | glVertexAttribPointer(GLuint(GLKVertexAttrib.color.rawValue), 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(6*MemoryLayout.size), UnsafeRawPointer.init(bitPattern: 12));
343 | }
344 |
345 | func setupGL() {
346 | EAGLContext.setCurrent(glContext);
347 | effect = GLKBaseEffect.init();
348 | self.updateStrokeColor();
349 |
350 | glDisable(GLenum(GL_DEPTH_TEST));
351 |
352 | glGenVertexArraysOES(1, &vertexArray);
353 | glBindVertexArrayOES(vertexArray);
354 |
355 | glGenBuffers(1, &vertexBuffer);
356 | glBindBuffer(GLenum(GL_ARRAY_BUFFER), vertexBuffer);
357 | glBufferData(GLenum(GL_ARRAY_BUFFER), MemoryLayout.size * maxLength, signatureVertexData, GLenum(GL_DYNAMIC_DRAW));
358 | self.bindShaderAttributes();
359 |
360 | glGenVertexArraysOES(1, &dotsArray);
361 | glBindVertexArrayOES(dotsArray);
362 |
363 | glGenBuffers(1, &dotsBuffer);
364 | glBindBuffer(GLenum(GL_ARRAY_BUFFER), dotsBuffer);
365 | glBufferData(GLenum(GL_ARRAY_BUFFER), MemoryLayout.size * maxLength, signatureDotsData, GLenum(GL_DYNAMIC_DRAW));
366 | self.bindShaderAttributes();
367 |
368 | glBindVertexArrayOES(0);
369 |
370 | let ortho : GLKMatrix4 = GLKMatrix4MakeOrtho(-1, 1, -1, 1, 0.1, 2.0);
371 | effect?.transform.projectionMatrix = ortho;
372 |
373 | let modelViewMatrix : GLKMatrix4 = GLKMatrix4MakeTranslation(0.0, 0.0, -1.0);
374 | effect?.transform.modelviewMatrix = modelViewMatrix;
375 |
376 | length = 0;
377 | penThickness = 0.003;
378 | previousPoint = CGPoint.init(x: -100, y: -100);
379 | }
380 |
381 | func addTriangleStripPointsForPrevious(previous : WFSignaturePoint, next : WFSignaturePoint) {
382 | var toTravel = penThickness / 2.0;
383 | for _ in 0 ... 1 {
384 | let p = perpendicular(p1: previous, p2: next);
385 | let p1 = next.vertex;
386 | let ref = GLKVector3Add(p1, p);
387 |
388 | let distance = GLKVector3Distance(p1, ref);
389 | var difX = p1.x - ref.x;
390 | var difY = p1.y - ref.y;
391 | let ratio = -1.0 * (toTravel / distance);
392 |
393 | difX = difX * ratio;
394 | difY = difY * ratio;
395 |
396 | var stripPoint = WFSignaturePoint.init(vertex: GLKVector3.init(v: (p1.x + difX, p1.y + difY, 0.0)), color: self.penColor);
397 | addVertex(length: &length, pointsArray: pointsArray, v: &stripPoint);
398 | toTravel *= -1;
399 | }
400 | }
401 |
402 | func tearDownGL() {
403 | EAGLContext.setCurrent(glContext);
404 | glDeleteVertexArraysOES(1, &vertexArray);
405 | glDeleteBuffers(1, &vertexBuffer);
406 |
407 | glDeleteVertexArraysOES(1, &dotsArray);
408 | glDeleteBuffers(1, &dotsBuffer);
409 |
410 | effect = nil;
411 | }
412 |
413 | /**
414 | *设置笔触颜色
415 | */
416 | public func setPenColor(color : UIColor) {
417 | var red : CGFloat = 0, green : CGFloat = 0, blue : CGFloat = 0, alpha : CGFloat = 0;
418 | color.getRed(&red, green: &green, blue: &blue, alpha: &alpha);
419 | self.penColor = GLKVector3.init(v: (Float(red), Float(green), Float(blue)));
420 | }
421 |
422 | /**
423 | *撤回最后一划
424 | */
425 | public func remove() {
426 | if pointsArray.count<=0 {
427 | return;
428 | }
429 | pointsArray.removeLast();
430 | self .setNeedsDisplay();
431 | }
432 | }
433 |
--------------------------------------------------------------------------------
/WFSignatureView/WFSignatureView.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 9E7A534F1F566EAA00D4FAFB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7A534E1F566EAA00D4FAFB /* AppDelegate.swift */; };
11 | 9E7A53511F566EAA00D4FAFB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7A53501F566EAA00D4FAFB /* ViewController.swift */; };
12 | 9E7A53541F566EAA00D4FAFB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9E7A53521F566EAA00D4FAFB /* Main.storyboard */; };
13 | 9E7A53561F566EAA00D4FAFB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9E7A53551F566EAA00D4FAFB /* Assets.xcassets */; };
14 | 9E7A53591F566EAA00D4FAFB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9E7A53571F566EAA00D4FAFB /* LaunchScreen.storyboard */; };
15 | 9E7A53641F566EAA00D4FAFB /* WFSignatureViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7A53631F566EAA00D4FAFB /* WFSignatureViewTests.swift */; };
16 | 9E7A536F1F566EAA00D4FAFB /* WFSignatureViewUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7A536E1F566EAA00D4FAFB /* WFSignatureViewUITests.swift */; };
17 | 9E7A537E1F566F6300D4FAFB /* WFSignatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7A537D1F566F6300D4FAFB /* WFSignatureView.swift */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXContainerItemProxy section */
21 | 9E7A53601F566EAA00D4FAFB /* PBXContainerItemProxy */ = {
22 | isa = PBXContainerItemProxy;
23 | containerPortal = 9E7A53431F566EAA00D4FAFB /* Project object */;
24 | proxyType = 1;
25 | remoteGlobalIDString = 9E7A534A1F566EAA00D4FAFB;
26 | remoteInfo = WFSignatureView;
27 | };
28 | 9E7A536B1F566EAA00D4FAFB /* PBXContainerItemProxy */ = {
29 | isa = PBXContainerItemProxy;
30 | containerPortal = 9E7A53431F566EAA00D4FAFB /* Project object */;
31 | proxyType = 1;
32 | remoteGlobalIDString = 9E7A534A1F566EAA00D4FAFB;
33 | remoteInfo = WFSignatureView;
34 | };
35 | /* End PBXContainerItemProxy section */
36 |
37 | /* Begin PBXFileReference section */
38 | 9E7A534B1F566EAA00D4FAFB /* WFSignatureView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WFSignatureView.app; sourceTree = BUILT_PRODUCTS_DIR; };
39 | 9E7A534E1F566EAA00D4FAFB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
40 | 9E7A53501F566EAA00D4FAFB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
41 | 9E7A53531F566EAA00D4FAFB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
42 | 9E7A53551F566EAA00D4FAFB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
43 | 9E7A53581F566EAA00D4FAFB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
44 | 9E7A535A1F566EAA00D4FAFB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
45 | 9E7A535F1F566EAA00D4FAFB /* WFSignatureViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WFSignatureViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
46 | 9E7A53631F566EAA00D4FAFB /* WFSignatureViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WFSignatureViewTests.swift; sourceTree = ""; };
47 | 9E7A53651F566EAA00D4FAFB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
48 | 9E7A536A1F566EAA00D4FAFB /* WFSignatureViewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WFSignatureViewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
49 | 9E7A536E1F566EAA00D4FAFB /* WFSignatureViewUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WFSignatureViewUITests.swift; sourceTree = ""; };
50 | 9E7A53701F566EAA00D4FAFB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
51 | 9E7A537D1F566F6300D4FAFB /* WFSignatureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WFSignatureView.swift; sourceTree = ""; };
52 | /* End PBXFileReference section */
53 |
54 | /* Begin PBXFrameworksBuildPhase section */
55 | 9E7A53481F566EAA00D4FAFB /* Frameworks */ = {
56 | isa = PBXFrameworksBuildPhase;
57 | buildActionMask = 2147483647;
58 | files = (
59 | );
60 | runOnlyForDeploymentPostprocessing = 0;
61 | };
62 | 9E7A535C1F566EAA00D4FAFB /* Frameworks */ = {
63 | isa = PBXFrameworksBuildPhase;
64 | buildActionMask = 2147483647;
65 | files = (
66 | );
67 | runOnlyForDeploymentPostprocessing = 0;
68 | };
69 | 9E7A53671F566EAA00D4FAFB /* Frameworks */ = {
70 | isa = PBXFrameworksBuildPhase;
71 | buildActionMask = 2147483647;
72 | files = (
73 | );
74 | runOnlyForDeploymentPostprocessing = 0;
75 | };
76 | /* End PBXFrameworksBuildPhase section */
77 |
78 | /* Begin PBXGroup section */
79 | 9E7A53421F566EAA00D4FAFB = {
80 | isa = PBXGroup;
81 | children = (
82 | 9E7A534D1F566EAA00D4FAFB /* WFSignatureView */,
83 | 9E7A53621F566EAA00D4FAFB /* WFSignatureViewTests */,
84 | 9E7A536D1F566EAA00D4FAFB /* WFSignatureViewUITests */,
85 | 9E7A534C1F566EAA00D4FAFB /* Products */,
86 | );
87 | sourceTree = "";
88 | };
89 | 9E7A534C1F566EAA00D4FAFB /* Products */ = {
90 | isa = PBXGroup;
91 | children = (
92 | 9E7A534B1F566EAA00D4FAFB /* WFSignatureView.app */,
93 | 9E7A535F1F566EAA00D4FAFB /* WFSignatureViewTests.xctest */,
94 | 9E7A536A1F566EAA00D4FAFB /* WFSignatureViewUITests.xctest */,
95 | );
96 | name = Products;
97 | sourceTree = "";
98 | };
99 | 9E7A534D1F566EAA00D4FAFB /* WFSignatureView */ = {
100 | isa = PBXGroup;
101 | children = (
102 | 9E7A537C1F566F5100D4FAFB /* source */,
103 | 9E7A534E1F566EAA00D4FAFB /* AppDelegate.swift */,
104 | 9E7A53501F566EAA00D4FAFB /* ViewController.swift */,
105 | 9E7A53521F566EAA00D4FAFB /* Main.storyboard */,
106 | 9E7A53551F566EAA00D4FAFB /* Assets.xcassets */,
107 | 9E7A53571F566EAA00D4FAFB /* LaunchScreen.storyboard */,
108 | 9E7A535A1F566EAA00D4FAFB /* Info.plist */,
109 | );
110 | path = WFSignatureView;
111 | sourceTree = "";
112 | };
113 | 9E7A53621F566EAA00D4FAFB /* WFSignatureViewTests */ = {
114 | isa = PBXGroup;
115 | children = (
116 | 9E7A53631F566EAA00D4FAFB /* WFSignatureViewTests.swift */,
117 | 9E7A53651F566EAA00D4FAFB /* Info.plist */,
118 | );
119 | path = WFSignatureViewTests;
120 | sourceTree = "";
121 | };
122 | 9E7A536D1F566EAA00D4FAFB /* WFSignatureViewUITests */ = {
123 | isa = PBXGroup;
124 | children = (
125 | 9E7A536E1F566EAA00D4FAFB /* WFSignatureViewUITests.swift */,
126 | 9E7A53701F566EAA00D4FAFB /* Info.plist */,
127 | );
128 | path = WFSignatureViewUITests;
129 | sourceTree = "";
130 | };
131 | 9E7A537C1F566F5100D4FAFB /* source */ = {
132 | isa = PBXGroup;
133 | children = (
134 | 9E7A537D1F566F6300D4FAFB /* WFSignatureView.swift */,
135 | );
136 | path = source;
137 | sourceTree = "";
138 | };
139 | /* End PBXGroup section */
140 |
141 | /* Begin PBXNativeTarget section */
142 | 9E7A534A1F566EAA00D4FAFB /* WFSignatureView */ = {
143 | isa = PBXNativeTarget;
144 | buildConfigurationList = 9E7A53731F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureView" */;
145 | buildPhases = (
146 | 9E7A53471F566EAA00D4FAFB /* Sources */,
147 | 9E7A53481F566EAA00D4FAFB /* Frameworks */,
148 | 9E7A53491F566EAA00D4FAFB /* Resources */,
149 | );
150 | buildRules = (
151 | );
152 | dependencies = (
153 | );
154 | name = WFSignatureView;
155 | productName = WFSignatureView;
156 | productReference = 9E7A534B1F566EAA00D4FAFB /* WFSignatureView.app */;
157 | productType = "com.apple.product-type.application";
158 | };
159 | 9E7A535E1F566EAA00D4FAFB /* WFSignatureViewTests */ = {
160 | isa = PBXNativeTarget;
161 | buildConfigurationList = 9E7A53761F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureViewTests" */;
162 | buildPhases = (
163 | 9E7A535B1F566EAA00D4FAFB /* Sources */,
164 | 9E7A535C1F566EAA00D4FAFB /* Frameworks */,
165 | 9E7A535D1F566EAA00D4FAFB /* Resources */,
166 | );
167 | buildRules = (
168 | );
169 | dependencies = (
170 | 9E7A53611F566EAA00D4FAFB /* PBXTargetDependency */,
171 | );
172 | name = WFSignatureViewTests;
173 | productName = WFSignatureViewTests;
174 | productReference = 9E7A535F1F566EAA00D4FAFB /* WFSignatureViewTests.xctest */;
175 | productType = "com.apple.product-type.bundle.unit-test";
176 | };
177 | 9E7A53691F566EAA00D4FAFB /* WFSignatureViewUITests */ = {
178 | isa = PBXNativeTarget;
179 | buildConfigurationList = 9E7A53791F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureViewUITests" */;
180 | buildPhases = (
181 | 9E7A53661F566EAA00D4FAFB /* Sources */,
182 | 9E7A53671F566EAA00D4FAFB /* Frameworks */,
183 | 9E7A53681F566EAA00D4FAFB /* Resources */,
184 | );
185 | buildRules = (
186 | );
187 | dependencies = (
188 | 9E7A536C1F566EAA00D4FAFB /* PBXTargetDependency */,
189 | );
190 | name = WFSignatureViewUITests;
191 | productName = WFSignatureViewUITests;
192 | productReference = 9E7A536A1F566EAA00D4FAFB /* WFSignatureViewUITests.xctest */;
193 | productType = "com.apple.product-type.bundle.ui-testing";
194 | };
195 | /* End PBXNativeTarget section */
196 |
197 | /* Begin PBXProject section */
198 | 9E7A53431F566EAA00D4FAFB /* Project object */ = {
199 | isa = PBXProject;
200 | attributes = {
201 | LastSwiftUpdateCheck = 0820;
202 | LastUpgradeCheck = 0820;
203 | ORGANIZATIONNAME = babywolf;
204 | TargetAttributes = {
205 | 9E7A534A1F566EAA00D4FAFB = {
206 | CreatedOnToolsVersion = 8.2.1;
207 | DevelopmentTeam = C63Y2RP62Y;
208 | ProvisioningStyle = Automatic;
209 | };
210 | 9E7A535E1F566EAA00D4FAFB = {
211 | CreatedOnToolsVersion = 8.2.1;
212 | DevelopmentTeam = C63Y2RP62Y;
213 | ProvisioningStyle = Automatic;
214 | TestTargetID = 9E7A534A1F566EAA00D4FAFB;
215 | };
216 | 9E7A53691F566EAA00D4FAFB = {
217 | CreatedOnToolsVersion = 8.2.1;
218 | DevelopmentTeam = C63Y2RP62Y;
219 | ProvisioningStyle = Automatic;
220 | TestTargetID = 9E7A534A1F566EAA00D4FAFB;
221 | };
222 | };
223 | };
224 | buildConfigurationList = 9E7A53461F566EAA00D4FAFB /* Build configuration list for PBXProject "WFSignatureView" */;
225 | compatibilityVersion = "Xcode 3.2";
226 | developmentRegion = English;
227 | hasScannedForEncodings = 0;
228 | knownRegions = (
229 | en,
230 | Base,
231 | );
232 | mainGroup = 9E7A53421F566EAA00D4FAFB;
233 | productRefGroup = 9E7A534C1F566EAA00D4FAFB /* Products */;
234 | projectDirPath = "";
235 | projectRoot = "";
236 | targets = (
237 | 9E7A534A1F566EAA00D4FAFB /* WFSignatureView */,
238 | 9E7A535E1F566EAA00D4FAFB /* WFSignatureViewTests */,
239 | 9E7A53691F566EAA00D4FAFB /* WFSignatureViewUITests */,
240 | );
241 | };
242 | /* End PBXProject section */
243 |
244 | /* Begin PBXResourcesBuildPhase section */
245 | 9E7A53491F566EAA00D4FAFB /* Resources */ = {
246 | isa = PBXResourcesBuildPhase;
247 | buildActionMask = 2147483647;
248 | files = (
249 | 9E7A53591F566EAA00D4FAFB /* LaunchScreen.storyboard in Resources */,
250 | 9E7A53561F566EAA00D4FAFB /* Assets.xcassets in Resources */,
251 | 9E7A53541F566EAA00D4FAFB /* Main.storyboard in Resources */,
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | 9E7A535D1F566EAA00D4FAFB /* Resources */ = {
256 | isa = PBXResourcesBuildPhase;
257 | buildActionMask = 2147483647;
258 | files = (
259 | );
260 | runOnlyForDeploymentPostprocessing = 0;
261 | };
262 | 9E7A53681F566EAA00D4FAFB /* Resources */ = {
263 | isa = PBXResourcesBuildPhase;
264 | buildActionMask = 2147483647;
265 | files = (
266 | );
267 | runOnlyForDeploymentPostprocessing = 0;
268 | };
269 | /* End PBXResourcesBuildPhase section */
270 |
271 | /* Begin PBXSourcesBuildPhase section */
272 | 9E7A53471F566EAA00D4FAFB /* Sources */ = {
273 | isa = PBXSourcesBuildPhase;
274 | buildActionMask = 2147483647;
275 | files = (
276 | 9E7A53511F566EAA00D4FAFB /* ViewController.swift in Sources */,
277 | 9E7A534F1F566EAA00D4FAFB /* AppDelegate.swift in Sources */,
278 | 9E7A537E1F566F6300D4FAFB /* WFSignatureView.swift in Sources */,
279 | );
280 | runOnlyForDeploymentPostprocessing = 0;
281 | };
282 | 9E7A535B1F566EAA00D4FAFB /* Sources */ = {
283 | isa = PBXSourcesBuildPhase;
284 | buildActionMask = 2147483647;
285 | files = (
286 | 9E7A53641F566EAA00D4FAFB /* WFSignatureViewTests.swift in Sources */,
287 | );
288 | runOnlyForDeploymentPostprocessing = 0;
289 | };
290 | 9E7A53661F566EAA00D4FAFB /* Sources */ = {
291 | isa = PBXSourcesBuildPhase;
292 | buildActionMask = 2147483647;
293 | files = (
294 | 9E7A536F1F566EAA00D4FAFB /* WFSignatureViewUITests.swift in Sources */,
295 | );
296 | runOnlyForDeploymentPostprocessing = 0;
297 | };
298 | /* End PBXSourcesBuildPhase section */
299 |
300 | /* Begin PBXTargetDependency section */
301 | 9E7A53611F566EAA00D4FAFB /* PBXTargetDependency */ = {
302 | isa = PBXTargetDependency;
303 | target = 9E7A534A1F566EAA00D4FAFB /* WFSignatureView */;
304 | targetProxy = 9E7A53601F566EAA00D4FAFB /* PBXContainerItemProxy */;
305 | };
306 | 9E7A536C1F566EAA00D4FAFB /* PBXTargetDependency */ = {
307 | isa = PBXTargetDependency;
308 | target = 9E7A534A1F566EAA00D4FAFB /* WFSignatureView */;
309 | targetProxy = 9E7A536B1F566EAA00D4FAFB /* PBXContainerItemProxy */;
310 | };
311 | /* End PBXTargetDependency section */
312 |
313 | /* Begin PBXVariantGroup section */
314 | 9E7A53521F566EAA00D4FAFB /* Main.storyboard */ = {
315 | isa = PBXVariantGroup;
316 | children = (
317 | 9E7A53531F566EAA00D4FAFB /* Base */,
318 | );
319 | name = Main.storyboard;
320 | sourceTree = "";
321 | };
322 | 9E7A53571F566EAA00D4FAFB /* LaunchScreen.storyboard */ = {
323 | isa = PBXVariantGroup;
324 | children = (
325 | 9E7A53581F566EAA00D4FAFB /* Base */,
326 | );
327 | name = LaunchScreen.storyboard;
328 | sourceTree = "";
329 | };
330 | /* End PBXVariantGroup section */
331 |
332 | /* Begin XCBuildConfiguration section */
333 | 9E7A53711F566EAA00D4FAFB /* Debug */ = {
334 | isa = XCBuildConfiguration;
335 | buildSettings = {
336 | ALWAYS_SEARCH_USER_PATHS = NO;
337 | CLANG_ANALYZER_NONNULL = YES;
338 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
339 | CLANG_CXX_LIBRARY = "libc++";
340 | CLANG_ENABLE_MODULES = YES;
341 | CLANG_ENABLE_OBJC_ARC = YES;
342 | CLANG_WARN_BOOL_CONVERSION = YES;
343 | CLANG_WARN_CONSTANT_CONVERSION = YES;
344 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
345 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
346 | CLANG_WARN_EMPTY_BODY = YES;
347 | CLANG_WARN_ENUM_CONVERSION = YES;
348 | CLANG_WARN_INFINITE_RECURSION = YES;
349 | CLANG_WARN_INT_CONVERSION = YES;
350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
351 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
352 | CLANG_WARN_UNREACHABLE_CODE = YES;
353 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
354 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
355 | COPY_PHASE_STRIP = NO;
356 | DEBUG_INFORMATION_FORMAT = dwarf;
357 | ENABLE_STRICT_OBJC_MSGSEND = YES;
358 | ENABLE_TESTABILITY = YES;
359 | GCC_C_LANGUAGE_STANDARD = gnu99;
360 | GCC_DYNAMIC_NO_PIC = NO;
361 | GCC_NO_COMMON_BLOCKS = YES;
362 | GCC_OPTIMIZATION_LEVEL = 0;
363 | GCC_PREPROCESSOR_DEFINITIONS = (
364 | "DEBUG=1",
365 | "$(inherited)",
366 | );
367 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
368 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
369 | GCC_WARN_UNDECLARED_SELECTOR = YES;
370 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
371 | GCC_WARN_UNUSED_FUNCTION = YES;
372 | GCC_WARN_UNUSED_VARIABLE = YES;
373 | IPHONEOS_DEPLOYMENT_TARGET = 10.2;
374 | MTL_ENABLE_DEBUG_INFO = YES;
375 | ONLY_ACTIVE_ARCH = YES;
376 | SDKROOT = iphoneos;
377 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
378 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
379 | TARGETED_DEVICE_FAMILY = "1,2";
380 | };
381 | name = Debug;
382 | };
383 | 9E7A53721F566EAA00D4FAFB /* Release */ = {
384 | isa = XCBuildConfiguration;
385 | buildSettings = {
386 | ALWAYS_SEARCH_USER_PATHS = NO;
387 | CLANG_ANALYZER_NONNULL = YES;
388 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
389 | CLANG_CXX_LIBRARY = "libc++";
390 | CLANG_ENABLE_MODULES = YES;
391 | CLANG_ENABLE_OBJC_ARC = YES;
392 | CLANG_WARN_BOOL_CONVERSION = YES;
393 | CLANG_WARN_CONSTANT_CONVERSION = YES;
394 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
395 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
396 | CLANG_WARN_EMPTY_BODY = YES;
397 | CLANG_WARN_ENUM_CONVERSION = YES;
398 | CLANG_WARN_INFINITE_RECURSION = YES;
399 | CLANG_WARN_INT_CONVERSION = YES;
400 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
401 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
402 | CLANG_WARN_UNREACHABLE_CODE = YES;
403 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
404 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
405 | COPY_PHASE_STRIP = NO;
406 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
407 | ENABLE_NS_ASSERTIONS = NO;
408 | ENABLE_STRICT_OBJC_MSGSEND = YES;
409 | GCC_C_LANGUAGE_STANDARD = gnu99;
410 | GCC_NO_COMMON_BLOCKS = YES;
411 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
412 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
413 | GCC_WARN_UNDECLARED_SELECTOR = YES;
414 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
415 | GCC_WARN_UNUSED_FUNCTION = YES;
416 | GCC_WARN_UNUSED_VARIABLE = YES;
417 | IPHONEOS_DEPLOYMENT_TARGET = 10.2;
418 | MTL_ENABLE_DEBUG_INFO = NO;
419 | SDKROOT = iphoneos;
420 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
421 | TARGETED_DEVICE_FAMILY = "1,2";
422 | VALIDATE_PRODUCT = YES;
423 | };
424 | name = Release;
425 | };
426 | 9E7A53741F566EAA00D4FAFB /* Debug */ = {
427 | isa = XCBuildConfiguration;
428 | buildSettings = {
429 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
430 | DEVELOPMENT_TEAM = C63Y2RP62Y;
431 | INFOPLIST_FILE = WFSignatureView/Info.plist;
432 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
433 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
434 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureView;
435 | PRODUCT_NAME = "$(TARGET_NAME)";
436 | SWIFT_VERSION = 3.0;
437 | };
438 | name = Debug;
439 | };
440 | 9E7A53751F566EAA00D4FAFB /* Release */ = {
441 | isa = XCBuildConfiguration;
442 | buildSettings = {
443 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
444 | DEVELOPMENT_TEAM = C63Y2RP62Y;
445 | INFOPLIST_FILE = WFSignatureView/Info.plist;
446 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
447 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
448 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureView;
449 | PRODUCT_NAME = "$(TARGET_NAME)";
450 | SWIFT_VERSION = 3.0;
451 | };
452 | name = Release;
453 | };
454 | 9E7A53771F566EAA00D4FAFB /* Debug */ = {
455 | isa = XCBuildConfiguration;
456 | buildSettings = {
457 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
458 | BUNDLE_LOADER = "$(TEST_HOST)";
459 | DEVELOPMENT_TEAM = C63Y2RP62Y;
460 | INFOPLIST_FILE = WFSignatureViewTests/Info.plist;
461 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
462 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureViewTests;
463 | PRODUCT_NAME = "$(TARGET_NAME)";
464 | SWIFT_VERSION = 3.0;
465 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WFSignatureView.app/WFSignatureView";
466 | };
467 | name = Debug;
468 | };
469 | 9E7A53781F566EAA00D4FAFB /* Release */ = {
470 | isa = XCBuildConfiguration;
471 | buildSettings = {
472 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
473 | BUNDLE_LOADER = "$(TEST_HOST)";
474 | DEVELOPMENT_TEAM = C63Y2RP62Y;
475 | INFOPLIST_FILE = WFSignatureViewTests/Info.plist;
476 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
477 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureViewTests;
478 | PRODUCT_NAME = "$(TARGET_NAME)";
479 | SWIFT_VERSION = 3.0;
480 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WFSignatureView.app/WFSignatureView";
481 | };
482 | name = Release;
483 | };
484 | 9E7A537A1F566EAA00D4FAFB /* Debug */ = {
485 | isa = XCBuildConfiguration;
486 | buildSettings = {
487 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
488 | DEVELOPMENT_TEAM = C63Y2RP62Y;
489 | INFOPLIST_FILE = WFSignatureViewUITests/Info.plist;
490 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
491 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureViewUITests;
492 | PRODUCT_NAME = "$(TARGET_NAME)";
493 | SWIFT_VERSION = 3.0;
494 | TEST_TARGET_NAME = WFSignatureView;
495 | };
496 | name = Debug;
497 | };
498 | 9E7A537B1F566EAA00D4FAFB /* Release */ = {
499 | isa = XCBuildConfiguration;
500 | buildSettings = {
501 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
502 | DEVELOPMENT_TEAM = C63Y2RP62Y;
503 | INFOPLIST_FILE = WFSignatureViewUITests/Info.plist;
504 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
505 | PRODUCT_BUNDLE_IDENTIFIER = com.weaver.WFSignatureViewUITests;
506 | PRODUCT_NAME = "$(TARGET_NAME)";
507 | SWIFT_VERSION = 3.0;
508 | TEST_TARGET_NAME = WFSignatureView;
509 | };
510 | name = Release;
511 | };
512 | /* End XCBuildConfiguration section */
513 |
514 | /* Begin XCConfigurationList section */
515 | 9E7A53461F566EAA00D4FAFB /* Build configuration list for PBXProject "WFSignatureView" */ = {
516 | isa = XCConfigurationList;
517 | buildConfigurations = (
518 | 9E7A53711F566EAA00D4FAFB /* Debug */,
519 | 9E7A53721F566EAA00D4FAFB /* Release */,
520 | );
521 | defaultConfigurationIsVisible = 0;
522 | defaultConfigurationName = Release;
523 | };
524 | 9E7A53731F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureView" */ = {
525 | isa = XCConfigurationList;
526 | buildConfigurations = (
527 | 9E7A53741F566EAA00D4FAFB /* Debug */,
528 | 9E7A53751F566EAA00D4FAFB /* Release */,
529 | );
530 | defaultConfigurationIsVisible = 0;
531 | };
532 | 9E7A53761F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureViewTests" */ = {
533 | isa = XCConfigurationList;
534 | buildConfigurations = (
535 | 9E7A53771F566EAA00D4FAFB /* Debug */,
536 | 9E7A53781F566EAA00D4FAFB /* Release */,
537 | );
538 | defaultConfigurationIsVisible = 0;
539 | };
540 | 9E7A53791F566EAA00D4FAFB /* Build configuration list for PBXNativeTarget "WFSignatureViewUITests" */ = {
541 | isa = XCConfigurationList;
542 | buildConfigurations = (
543 | 9E7A537A1F566EAA00D4FAFB /* Debug */,
544 | 9E7A537B1F566EAA00D4FAFB /* Release */,
545 | );
546 | defaultConfigurationIsVisible = 0;
547 | };
548 | /* End XCConfigurationList section */
549 | };
550 | rootObject = 9E7A53431F566EAA00D4FAFB /* Project object */;
551 | }
552 |
--------------------------------------------------------------------------------