Skip to content

Commit 479a624

Browse files
committed
Able to add dot in signature in both Objective-C and Swift version.
1 parent 16db7e6 commit 479a624

File tree

6 files changed

+100
-313
lines changed

6 files changed

+100
-313
lines changed

Examples/Objective-C/signature/signature.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
0BDA12901C6B17EC00B26797 /* Project object */ = {
272272
isa = PBXProject;
273273
attributes = {
274-
LastUpgradeCheck = 0710;
274+
LastUpgradeCheck = 0830;
275275
ORGANIZATIONNAME = vigneshuvi;
276276
TargetAttributes = {
277277
0BDA12971C6B17EC00B26797 = {
@@ -412,8 +412,10 @@
412412
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
413413
CLANG_WARN_EMPTY_BODY = YES;
414414
CLANG_WARN_ENUM_CONVERSION = YES;
415+
CLANG_WARN_INFINITE_RECURSION = YES;
415416
CLANG_WARN_INT_CONVERSION = YES;
416417
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
418+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
417419
CLANG_WARN_UNREACHABLE_CODE = YES;
418420
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
419421
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -456,8 +458,10 @@
456458
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
457459
CLANG_WARN_EMPTY_BODY = YES;
458460
CLANG_WARN_ENUM_CONVERSION = YES;
461+
CLANG_WARN_INFINITE_RECURSION = YES;
459462
CLANG_WARN_INT_CONVERSION = YES;
460463
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
464+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
461465
CLANG_WARN_UNREACHABLE_CODE = YES;
462466
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
463467
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";

Lib/Objective-C/UviSignatureView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
@property (nonatomic) CGFloat lineWidth;
2626
@property (nonatomic, readonly) BOOL signatureExists;
2727
- (void)captureSignature;
28-
- (UIImage*)signatureImage:(CGPoint)position text:(NSString*)text;
28+
- (UIImage*_Nullable)signatureImage:(CGPoint)position text:(NSString*_Nullable)text;
2929

3030
@end

Lib/Objective-C/UviSignatureView.m

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ - (void)initialize {
3939
[signPath setLineCapStyle:kCGLineCapRound];
4040
[signPath setLineJoinStyle:kCGLineJoinRound];
4141

42+
// Added the Tap Reconginzer for capture the touches
43+
UITapGestureRecognizer *tapReconizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapReconizer:)];
44+
[tapReconizer setNumberOfTouchesRequired : 1];
45+
[tapReconizer setNumberOfTapsRequired: 1];
46+
[self addGestureRecognizer:tapReconizer];
47+
4248
// Added the Pan Reconginzer for capture the touches
4349
UIPanGestureRecognizer *panReconizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panReconizer:)];
4450
panReconizer.maximumNumberOfTouches = panReconizer.minimumNumberOfTouches = 1;
@@ -47,10 +53,9 @@ - (void)initialize {
4753
// Erase when long press the view.
4854
[self addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(erase)]];
4955

50-
// Erase when double tap the view.
51-
UITapGestureRecognizer *tapReconizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(erase)];
52-
[tapReconizer setNumberOfTouchesRequired : 2];
53-
[self addGestureRecognizer:tapReconizer];
56+
// Erase when long press view.
57+
UILongPressGestureRecognizer *longReconizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(erase)];
58+
[self addGestureRecognizer:longReconizer];
5459

5560
// Erase the view when recieving a notification named "shake" from the NSNotificationCenter object
5661
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(erase) name:@"shake" object:nil];
@@ -157,11 +162,24 @@ - (void)erase {
157162
[self setNeedsDisplay]; // Update the view.
158163
}
159164

165+
// panReconizer method triggers while touch the view.
166+
- (void)tapReconizer:(UITapGestureRecognizer *)tab {
167+
168+
CGPoint currentPoint = [tab locationInView:self];
169+
170+
CGPoint prevPoint = CGPointMake(currentPoint.x, currentPoint.y-2);
171+
CGPoint midPoint = midpoint(currentPoint, prevPoint);
172+
[signPath moveToPoint:currentPoint];
173+
[signPath addLineToPoint:midPoint];
174+
175+
[self setNeedsDisplay]; // Update the view.
176+
}
177+
160178
// panReconizer method triggers while touch the view.
161179
- (void)panReconizer:(UIPanGestureRecognizer *)pan {
162180

163181
CGPoint currentPoint = [pan locationInView:self];
164-
CGPoint midPoint = midpoint(previousPoint, currentPoint);
182+
CGPoint midPoint = midpoint(currentPoint, previousPoint);
165183

166184
switch (pan.state) {
167185
case UIGestureRecognizerStateBegan:

Lib/Swift/UviSignatureView.swift

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// UviSignatureView.swift
33
// signature
44
//
@@ -8,10 +8,10 @@
88

99
import UIKit
1010
import QuartzCore
11-
11+
1212

1313
public let USER_SIGNATURE_PATH = "user_signature_path"
14-
14+
1515
@IBDesignable
1616
public class UviSignatureView: UIView {
1717
var signPath: UIBezierPath = UIBezierPath()
@@ -51,24 +51,30 @@ public class UviSignatureView: UIView {
5151
let mid :CGPoint = CGPoint.init(x: ((p0.x + p1.x) / 2.0), y: ((p0.y + p1.y) / 2.0))
5252
return mid;
5353
}
54-
55-
// Configurate the line Width
56-
internal func initialize() {
54+
55+
// Configurate the line Width
56+
internal func initialize() {
5757
signPath = UIBezierPath();
5858
signPath.lineWidth = 2.0; // Configurate the line Width
5959
self.isUserInteractionEnabled = true;
6060
previousPoint = CGPoint.init(x: 0, y: 0);
6161
pathArray = NSMutableArray();
62-
62+
6363
// Added the Pan Reconginzer for capture the touches
6464
let panRecognizer = UIPanGestureRecognizer(target:self, action:#selector(UviSignatureView.panRecognizer(_:)))
6565
panRecognizer.minimumNumberOfTouches = 1
6666
self.addGestureRecognizer(panRecognizer);
67-
67+
68+
let tabRecognizer = UITapGestureRecognizer(target:self, action:#selector(UviSignatureView.handleTap(_:)))
69+
tabRecognizer.numberOfTapsRequired = 1;
70+
tabRecognizer.numberOfTouchesRequired = 1;
71+
self.addGestureRecognizer(tabRecognizer);
72+
6873

6974
// Erase when long press the view.
7075
let eraseRecognizer = UILongPressGestureRecognizer(target:self, action:#selector(UviSignatureView.eraseRecognizer(_:)))
71-
self.addGestureRecognizer(eraseRecognizer);
76+
77+
self.addGestureRecognizer(eraseRecognizer);
7278

7379

7480
// Erase the view when recieving a notification named "shake" from the NSNotificationCenter object
@@ -96,20 +102,20 @@ public class UviSignatureView: UIView {
96102
var bgLinges = NSArray();
97103
let width:CGFloat = self.bounds.size.width;
98104
let height:CGFloat = self.bounds.size.height;
99-
105+
100106
let path:UIBezierPath = UIBezierPath();
101-
107+
102108
let bottom:CGFloat = 0.90;
103-
109+
104110
let x1:CGFloat = 0;
105111
let x2:CGFloat = width;
106-
112+
107113
let y1:CGFloat = height*bottom;
108114
let y2:CGFloat = height*bottom;
109-
115+
110116
path.move(to: CGPoint(x: x1, y: y1));
111117
path.addLine(to: CGPoint(x: x2, y: y2));
112-
118+
113119
bgLinges = [path];
114120
return bgLinges;
115121
}
@@ -126,31 +132,42 @@ public class UviSignatureView: UIView {
126132

127133
return pathArray;
128134
}
129-
135+
136+
func handleTap(_ recognizer: UITapGestureRecognizer) {
137+
// handling code
138+
let currentPoint = recognizer.location(in: self);
139+
let previousPoint:CGPoint = CGPoint(x: currentPoint.x, y: currentPoint.y-3);
140+
let midPoint:CGPoint = midpoint(previousPoint, p1: currentPoint)
141+
signPath.move(to: currentPoint)
142+
signPath.addLine(to: midPoint);
143+
144+
self.setNeedsDisplay(); // Update the view.
145+
}
146+
130147
// panReconizer method triggers while touch the view.
131148
func panRecognizer(_ recognizer:UIPanGestureRecognizer) {
132149
let currentPoint = recognizer.location(in: self);
133150
let midPoint:CGPoint = midpoint(previousPoint, p1: currentPoint)
134151

135152
switch(recognizer.state) {
136-
case UIGestureRecognizerState.began:
137-
signPath.move(to: currentPoint)
138-
break;
153+
case UIGestureRecognizerState.began:
154+
signPath.move(to: currentPoint)
155+
break;
139156

140-
case UIGestureRecognizerState.changed:
141-
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
142-
break;
157+
case UIGestureRecognizerState.changed:
158+
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
159+
break;
143160

144-
case UIGestureRecognizerState.ended:
145-
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
146-
break;
161+
case UIGestureRecognizerState.ended:
162+
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
163+
break;
147164

148-
case UIGestureRecognizerState.possible:
149-
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
150-
break;
165+
case UIGestureRecognizerState.possible:
166+
signPath.addQuadCurve(to: midPoint, controlPoint: previousPoint);
167+
break;
151168

152-
default:
153-
break;
169+
default:
170+
break;
154171
}
155172

156173
previousPoint = currentPoint;
@@ -165,7 +182,7 @@ public class UviSignatureView: UIView {
165182

166183
// Erase the Siganture view by initial the new path.
167184
internal func erase() {
168-
//signPath.closePath()
185+
//signPath.closePath()
169186
UserDefaults.standard.removeObject(forKey: USER_SIGNATURE_PATH);
170187
UserDefaults.standard.synchronize();
171188
pathArray.removeAllObjects();
@@ -187,7 +204,7 @@ public class UviSignatureView: UIView {
187204

188205
public func signatureImage(_ text : NSString, position : CGPoint)-> UIImage {
189206
UIGraphicsBeginImageContext(self.bounds.size);
190-
207+
191208
if(!text.isEqual(to: "")) {
192209
// Setup the font specific variables
193210
let attributes :[String:AnyObject] = [
@@ -197,21 +214,21 @@ public class UviSignatureView: UIView {
197214
]
198215
text.draw(at: position, withAttributes: attributes);
199216
}
200-
217+
201218

202219
for path in (self.pathArray) {
203220
self.lineColor.setStroke();
204221
(path as AnyObject).stroke();
205222
}
206-
207-
223+
224+
208225

209226
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;
210227
UIGraphicsEndImageContext();
211228
return image;
212229
}
213-
214-
230+
231+
215232
// Only override drawRect: if you perform custom drawing.
216233
// An empty implementation adversely affects performance during animation.
217234
override public func draw(_ rect: CGRect) {
@@ -229,13 +246,13 @@ public class UviSignatureView: UIView {
229246

230247
if (!self.signatureExists() && self.signPath.isEmpty) {
231248

232-
// Setup the font specific variables
233-
let attributes :[String:AnyObject] = [
234-
NSFontAttributeName : UIFont(name: "Helvetica", size: 12)!,
235-
NSStrokeWidthAttributeName : 0 as AnyObject,
236-
NSForegroundColorAttributeName : UIColor.black.withAlphaComponent(0.2)
237-
]
238-
placeHolderString.draw(at: self.placeholderPoint(), withAttributes: attributes);
249+
// Setup the font specific variables
250+
let attributes :[String:AnyObject] = [
251+
NSFontAttributeName : UIFont(name: "Helvetica", size: 12)!,
252+
NSStrokeWidthAttributeName : 0 as AnyObject,
253+
NSForegroundColorAttributeName : UIColor.black.withAlphaComponent(0.2)
254+
]
255+
placeHolderString.draw(at: self.placeholderPoint(), withAttributes: attributes);
239256

240257
}
241258

@@ -247,8 +264,8 @@ public class UviSignatureView: UIView {
247264

248265
self.lineColor.setStroke();
249266
signPath.stroke();
250-
267+
251268
}
252-
253-
269+
270+
254271
}

iOSSignatureCapture/iOSSignatureCapture.xcodeproj/project.pbxproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0B5DC1E41EB9ADA6005C31B3 /* UviSignatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B5DC1E31EB9ADA6005C31B3 /* UviSignatureView.swift */; };
1011
0BABD9DC1E924C0800046FC0 /* iOSSignatureCapture.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0BABD9D21E924C0800046FC0 /* iOSSignatureCapture.framework */; };
1112
0BABD9E11E924C0800046FC0 /* iOSSignatureCaptureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BABD9E01E924C0800046FC0 /* iOSSignatureCaptureTests.swift */; };
1213
0BABD9E31E924C0800046FC0 /* iOSSignatureCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 0BABD9D51E924C0800046FC0 /* iOSSignatureCapture.h */; settings = {ATTRIBUTES = (Public, ); }; };
13-
0BABD9ED1E924C4600046FC0 /* UviSignatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BABD9EC1E924C4600046FC0 /* UviSignatureView.swift */; };
1414
/* End PBXBuildFile section */
1515

1616
/* Begin PBXContainerItemProxy section */
@@ -24,13 +24,13 @@
2424
/* End PBXContainerItemProxy section */
2525

2626
/* Begin PBXFileReference section */
27+
0B5DC1E31EB9ADA6005C31B3 /* UviSignatureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UviSignatureView.swift; path = ../../Lib/Swift/UviSignatureView.swift; sourceTree = "<group>"; };
2728
0BABD9D21E924C0800046FC0 /* iOSSignatureCapture.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = iOSSignatureCapture.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2829
0BABD9D51E924C0800046FC0 /* iOSSignatureCapture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iOSSignatureCapture.h; sourceTree = "<group>"; };
2930
0BABD9D61E924C0800046FC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3031
0BABD9DB1E924C0800046FC0 /* iOSSignatureCaptureTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSSignatureCaptureTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3132
0BABD9E01E924C0800046FC0 /* iOSSignatureCaptureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSSignatureCaptureTests.swift; sourceTree = "<group>"; };
3233
0BABD9E21E924C0800046FC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
33-
0BABD9EC1E924C4600046FC0 /* UviSignatureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UviSignatureView.swift; sourceTree = "<group>"; };
3434
/* End PBXFileReference section */
3535

3636
/* Begin PBXFrameworksBuildPhase section */
@@ -73,7 +73,7 @@
7373
0BABD9D41E924C0800046FC0 /* iOSSignatureCapture */ = {
7474
isa = PBXGroup;
7575
children = (
76-
0BABD9EC1E924C4600046FC0 /* UviSignatureView.swift */,
76+
0B5DC1E31EB9ADA6005C31B3 /* UviSignatureView.swift */,
7777
0BABD9D51E924C0800046FC0 /* iOSSignatureCapture.h */,
7878
0BABD9D61E924C0800046FC0 /* Info.plist */,
7979
);
@@ -152,7 +152,7 @@
152152
0BABD9D11E924C0800046FC0 = {
153153
CreatedOnToolsVersion = 8.1;
154154
DevelopmentTeam = 7FUQA46NH7;
155-
LastSwiftMigration = 0810;
155+
LastSwiftMigration = 0830;
156156
ProvisioningStyle = Automatic;
157157
};
158158
0BABD9DA1E924C0800046FC0 = {
@@ -202,7 +202,7 @@
202202
isa = PBXSourcesBuildPhase;
203203
buildActionMask = 2147483647;
204204
files = (
205-
0BABD9ED1E924C4600046FC0 /* UviSignatureView.swift in Sources */,
205+
0B5DC1E41EB9ADA6005C31B3 /* UviSignatureView.swift in Sources */,
206206
);
207207
runOnlyForDeploymentPostprocessing = 0;
208208
};
@@ -412,6 +412,7 @@
412412
0BABD9E81E924C0800046FC0 /* Release */,
413413
);
414414
defaultConfigurationIsVisible = 0;
415+
defaultConfigurationName = Release;
415416
};
416417
0BABD9E91E924C0800046FC0 /* Build configuration list for PBXNativeTarget "iOSSignatureCaptureTests" */ = {
417418
isa = XCConfigurationList;
@@ -420,6 +421,7 @@
420421
0BABD9EB1E924C0800046FC0 /* Release */,
421422
);
422423
defaultConfigurationIsVisible = 0;
424+
defaultConfigurationName = Release;
423425
};
424426
/* End XCConfigurationList section */
425427
};

0 commit comments

Comments
 (0)