Skip to content

Commit

Permalink
Merge pull request #38 from GJNilsen/Development
Browse files Browse the repository at this point in the history
Minor bugfix
  • Loading branch information
GJ Nilsen authored Jun 14, 2017
2 parents b8b0c1b + 74947f5 commit 06c27a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ YPDrawSignatureView is available under the MIT license. See the [LICENSE](LICENS

## Update history

### v1.1.1 - 5/23/17
### v1.1.2 - 6/16/17

* Minor bugfix.

#### v1.1.1 - 5/23/17

* Bugfix

Expand Down
12 changes: 7 additions & 5 deletions SignatureTest/SignatureTest/YPDrawSignatureView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// YPDrawSignatureView is open source
// Version 1.1.1
// Version 1.1.2
//
// Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors
// Available under the MIT license
Expand Down Expand Up @@ -71,14 +71,16 @@ final public class YPDrawSignatureView: UIView {
super.init(coder: aDecoder)

path.lineWidth = strokeWidth
path.lineJoinStyle = CGLineJoin.round
path.lineJoinStyle = .round
path.lineCapStyle = .round
}

override public init(frame: CGRect) {
super.init(frame: frame)

path.lineWidth = strokeWidth
path.lineJoinStyle = CGLineJoin.round
path.lineJoinStyle = .round
path.lineCapStyle = .round
}

// MARK: - Draw
Expand Down Expand Up @@ -123,8 +125,8 @@ final public class YPDrawSignatureView: UIView {
override public func touchesEnded(_ touches: Set <UITouch>, with event: UIEvent?) {
if controlPoint < 4 {
let touchPoint = points[0]
path.move(to: CGPoint(x: touchPoint.x-1.0,y: touchPoint.y))
path.addLine(to: CGPoint(x: touchPoint.x+1.0,y: touchPoint.y))
path.move(to: CGPoint(x: touchPoint.x,y: touchPoint.y))
path.addLine(to: CGPoint(x: touchPoint.x,y: touchPoint.y))
setNeedsDisplay()
} else {
controlPoint = 0
Expand Down
70 changes: 36 additions & 34 deletions Sources/YPDrawSignatureView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// YPDrawSignatureView is open source
// Version 1.1.1
// Version 1.1.2
//
// Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors
// Available under the MIT license
Expand Down Expand Up @@ -32,28 +32,28 @@ final public class YPDrawSignatureView: UIView {
// MARK: - Public properties
@IBInspectable public var strokeWidth: CGFloat = 2.0 {
didSet {
self.path.lineWidth = strokeWidth
path.lineWidth = strokeWidth
}
}

@IBInspectable public var strokeColor: UIColor = .black {
didSet {
self.strokeColor.setStroke()
strokeColor.setStroke()
}
}

@objc
@available(*, deprecated, renamed: "backgroundColor")
@IBInspectable public var signatureBackgroundColor: UIColor = .white {
didSet {
self.backgroundColor = signatureBackgroundColor
backgroundColor = signatureBackgroundColor
}
}

// Computed Property returns true if the view actually contains a signature
public var doesContainSignature: Bool {
get {
if self.path.isEmpty {
if path.isEmpty {
return false
} else {
return true
Expand All @@ -70,15 +70,17 @@ final public class YPDrawSignatureView: UIView {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

self.path.lineWidth = self.strokeWidth
self.path.lineJoinStyle = CGLineJoin.round
path.lineWidth = strokeWidth
path.lineJoinStyle = .round
path.lineCapStyle = .round
}

override public init(frame: CGRect) {
super.init(frame: frame)

self.path.lineWidth = self.strokeWidth
self.path.lineJoinStyle = CGLineJoin.round
path.lineWidth = strokeWidth
path.lineJoinStyle = .round
path.lineCapStyle = .round
}

// MARK: - Draw
Expand All @@ -91,46 +93,46 @@ final public class YPDrawSignatureView: UIView {
override public func touchesBegan(_ touches: Set <UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first {
let touchPoint = firstTouch.location(in: self)
self.controlPoint = 0
self.points[0] = touchPoint
controlPoint = 0
points[0] = touchPoint
}

if let delegate = self.delegate {
if let delegate = delegate {
delegate.didStart()
}
}

override public func touchesMoved(_ touches: Set <UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first {
let touchPoint = firstTouch.location(in: self)
self.controlPoint += 1
self.points[self.controlPoint] = touchPoint
if (self.controlPoint == 4) {
self.points[3] = CGPoint(x: (self.points[2].x + self.points[4].x)/2.0, y: (self.points[2].y + self.points[4].y)/2.0)
self.path.move(to: self.points[0])
self.path.addCurve(to: self.points[3], controlPoint1:self.points[1], controlPoint2:self.points[2])
controlPoint += 1
points[controlPoint] = touchPoint
if (controlPoint == 4) {
points[3] = CGPoint(x: (points[2].x + points[4].x)/2.0, y: (points[2].y + points[4].y)/2.0)
path.move(to: points[0])
path.addCurve(to: points[3], controlPoint1: points[1], controlPoint2: points[2])

self.setNeedsDisplay()
self.points[0] = self.points[3]
self.points[1] = self.points[4]
self.controlPoint = 1
setNeedsDisplay()
points[0] = points[3]
points[1] = points[4]
controlPoint = 1
}

self.setNeedsDisplay()
setNeedsDisplay()
}
}

override public func touchesEnded(_ touches: Set <UITouch>, with event: UIEvent?) {
if self.controlPoint < 4 {
let touchPoint = self.points[0]
self.path.move(to: CGPoint(x: touchPoint.x-1.0,y: touchPoint.y))
self.path.addLine(to: CGPoint(x: touchPoint.x+1.0,y: touchPoint.y))
self.setNeedsDisplay()
if controlPoint < 4 {
let touchPoint = points[0]
path.move(to: CGPoint(x: touchPoint.x,y: touchPoint.y))
path.addLine(to: CGPoint(x: touchPoint.x,y: touchPoint.y))
setNeedsDisplay()
} else {
self.controlPoint = 0
controlPoint = 0
}

if let delegate = self.delegate {
if let delegate = delegate {
delegate.didFinish()
}
}
Expand Down Expand Up @@ -180,14 +182,14 @@ final public class YPDrawSignatureView: UIView {

guard let dataConsumer = CGDataConsumer.init(data: mutableData!) else { fatalError() }

var rect = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)
var rect = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)

guard let pdfContext = CGContext(consumer: dataConsumer, mediaBox: &rect, nil) else { fatalError() }

pdfContext.beginPDFPage(nil)
pdfContext.translateBy(x: 0, y: self.frame.height)
pdfContext.translateBy(x: 0, y: frame.height)
pdfContext.scaleBy(x: 1, y: -1)
pdfContext.addPath(self.path.cgPath)
pdfContext.addPath(path.cgPath)
pdfContext.setStrokeColor(strokeColor.cgColor)
pdfContext.strokePath()
pdfContext.saveGState()
Expand All @@ -198,7 +200,7 @@ final public class YPDrawSignatureView: UIView {

return data
}

}

// MARK: - Protocol definition for YPDrawSignatureViewDelegate
Expand Down

0 comments on commit 06c27a0

Please sign in to comment.