GithubHelp home page GithubHelp logo

alankarmisra / swiftsignatureview Goto Github PK

View Code? Open in Web Editor NEW
314.0 10.0 92.0 222 KB

A lightweight, fast and customizable option for capturing fluid, variable-stroke-width signatures within your app.

License: MIT License

Ruby 5.05% Swift 94.95%

swiftsignatureview's Introduction

SwiftSignatureView (now with PencilKit!)

Version License Platform

Description

SwiftSignatureView is a lightweight, fast and customizable option for capturing signatures within your app. You can retrieve the signature as a UIImage. With code that varies the pen width based on the speed of the finger movement, the view generates fluid, natural looking signatures. And now, with iOS13+, SwiftSignatureView automatically uses PencilKit to provide a native and even more fluid signature experience, including a natural integration with the Apple Pencil which makes SwiftSignatureView even better!

Sample

Version 3.2.1

  • Minor bug fixes.

Version 3.2.0

  • WARNING: This update changes the SwiftSignatureViewDelegate interface. Use the swiftSignatureViewDidDrawGesture to receive gesture events. In PencilKit (iOS13+) you get an additional swiftSignatureViewDidDraw event when the user ends a drawing sequence with the tool they were using.
  • Added Undo/Redo.
  • Added isEmpty to determine if the signature canvas is empty.
  • Fixed the constraints of the demo app.
  • Views and canvas are configured internally only using constraint layout.
  • Swiftlint fixes applied.
  • Added a page sheet version explaining how to use the library purely by code.
  • Added crop function for the PencilKit version (with resolution of the signature sorted).

Version 3.0.0

  • SwiftSignatureView now uses PencilKit for iOS13+ to provide a native and even more fluid signature experience, including a natural integration with the Apple Pencil.

Known issues

  • Currently the getCroppedSignature method won't work as expected with iOS13+ and instead returns the uncropped image.

Version 2.2.3 | Swift 5.0

  • SwiftSignatureView now draws from the point of touch instead of the point from where the pan gesture was recognized.

Version 2.2.2 | Swift 5.0

  • Modified the swiftSignatureViewDidPanInside delegate method to include the pan gesture recognizer in the callback. Warning: This will change the interface!

Version 2.2.0 | Swift 5.0

  • Added a getCroppedSignature method to get a UIImage of the signature with surrounding whitespace trimmed
  • Made the signature image publicly settable
  • Modified the example to demonstrate the cropped signature function

[ A big thank you to all the contributors. I know I don't say it enough. ]

Version 2.1.0 | Swift 5.0

  • Updated the Pod to Swift 5.0 syntax. The interface remains unchanged.

Version 2.0 | Swift 3.0 / XCode 8

  • Upgraded the Pod to Swift 3.0 syntax. The interface remains unchanged.

Version 1.0.3 | Swift 2.3 / XCode 8 compatibility

  • Upgraded the Example to use XCode 8 Storyboards. The SwiftSignatureView class file, however, remains unchanged when 'upgraded' to Swift 2.3.

Version 1.0.2 | Callbacks for panning/tapping

  • Added delegate for callbacks on panning/tapping.

Version 1.0.1 | Bug fixes and Syntax updates to Swift 2.2

  • Fixes an issue where the signature might appear blurred on retina displays
  • Updates the syntax to Swift 2.2
  • Fixes pod spec to make it compatible with Cocoapods 1.0

Version 0.0.8 | Bug fixes

Version 0.0.8 fixes a bug that caused SwiftSignatureView to compute incorrect offsets when not in full-screen mode. A big thank you to Todd Kersey for discovering the bug and suggesting a fix. This update fixes the issue.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

More specifically, you simply assign the SwiftSignatureView class to a UIView, optionally play with the minimum stroke width, maximum stroke width, stroke color and stroke alpha all which are settable from within the Interface Builder itself and you're all set! You can then use the signature property to get a UIImage representation of the signature and the clear method to clear the signature view. For example if you had:

@IBOutlet weak var signatureView: SwiftSignatureView!

you can use

signatureView.signature()

to get a UIImage representation of the signature;

signatureView.getCroppedSignature()

to get a UIImage representation of the cropped signature with the surrounding whitespace trimmed.

signatureView.clear()

to clear the signature view.

Installation

SwiftSignatureView is available through CocoaPods and Swift Package Manager.

For Cocoapods >= 1.0

Add the following lines to your Podfile:

use_frameworks!
target "YOUR_PROJECT_NAME" do
    pod "SwiftSignatureView"
end

For Cocoapods < 1.0

Add the following lines to your Podfile:

use_frameworks!
pod "SwiftSignatureView"

For Swift Package Manager

Add the following lines to your Package.swift file (or just use the Package Manager from within XCode and reference this repo):

dependencies: [
    .package(url: "https://github.com/alankarmisra/SwiftSignatureView.git", from: "3.2.1")
]

Questions? Write in to:

Alankar Misra, [email protected]

License

SwiftSignatureView is available under the MIT license. See the LICENSE file for more info.

swiftsignatureview's People

Contributors

alankarmisra avatar alistra avatar arturgrigor avatar chrisgrant avatar erickuck avatar paranat avatar paweldudek avatar ppamorim avatar readmecritic avatar scottcc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftsignatureview's Issues

Unknown Class in interface builder file

Hello,

I am trying to resolve the issue where IB cannot seem to find the SwiftSignatureView. I can find it in the class selector and access it through code. It builds and compiles without any issues, but when run it throws that message in the output window.

I read the prior closed report of this issue and attempted that solution and it didn't work. I was wondering if you had any other ideas that I could try?

Thanks.

Huge Lag in iPhone X

Good Afternoon,

I am using this library over a pet project, and found that in iPhone X its having huge lag, say if i write 3 Letters, the Signing starts at First Letter.

Can you please try to reproduce the same and please release it in a patch.

Thanks!

Stroke color on Dark Mode

I'm setting the stroke color to aways be an almost black color and the background to be white. But when the device is in dark mode, the background remains white and the stroke color does not remains the black one, it is set to a light gray or a black with a low opacity value (see screenshot). Is there any way to solve this?

Dark mode:
DE468100-46BB-4FEB-80FC-F8C6CECFA0D1_1_201_a

Light mode:
22F0A44E-0F58-4D66-9715-BFC680FB36F1_1_201_a

Fresh install seems to think pod is not using Swift 3.0

Getting the following compile-time error in SwiftSignatureView

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

This is on a newly-imaged machine with a completely fresh install of everything.

When I open the xcworkspace, I get a prompt to convert to swift 3, when I comply with the conversion- I get a ton of breaking changes, things like Expressions are not allowed at the top level

[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1580: failed assertion

Hello there. I encountered this issue when I'm trying to call getCroppedSignature(). It didn't happen all the time but when it did, the app crashed (signal SIGBART). Compiler showed error in PencilKitSignatureView.swift, open func getCroppedSignature(), line 70.
Detailed information in console:
2022-10-18 14:09:29.706342+0800 XXXXXXXX[793:258910] [Unknown process name] CGBitmapContextInfoCreate: unable to allocate 84965440 bytes for bitmap data
-[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1580: failed assertion Set Render Pipeline State Validation For color attachment 0, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set. the pipelineState's per sample imageBlock usage(10) is greater than the encoder's perSample imageBlock usage(6) ' dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib -[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1580: failed assertion Set Render Pipeline State Validation
For color attachment 0, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set.
the pipelineState's per sample imageBlock usage(10) is greater than the encoder's perSample imageBlock usage(6)
I couldn't find any useful information online. Is there anyone who can help me with this issue??

Installing the CocoaPod

Hello,
I can't seem to get the cocoapod to install this correctly. When I add this to the Podfile and do a pod install, I see a new framework marked Red called Pods_'APP_NAME'.framework.

Any suggestions on how to resolve?

Swift 2.3 / 3 Support

Hi,

I just like to know how your plans are about releasing a Swift 2.3 / Swift 3 compatible version?

Thanks,

Tobi

signature is blank image on iOS14

This only happens on iOS14. SwiftSignatureView's signature returns an UIImage, but it is blank.
LegancySwiftSignatureView works, returns the signature image correctly.

Save the signatureView.signature as a binding variable for another view.

XCode: 14.3.1
SwiftSignatureView: 3.2.0

Hello,

I am saving the signatureView.signature into a variable and outputting it directly as an image.

// ... code ...
@State private var signatureImage: UIImage?
@Binding var signature: String 
// ... code ... /
SignatureCaptureView(signatureImage: $signatureImage)
                .frame(height: 200)
                .border(Color.gray, width: 1)
// ... code ...
if let img = signatureImage {
      Image(uiImage: img)
          .resizable()
          .scaledToFit()
          .frame(width: 300, height: 200)
          .background(Color.gray.opacity(0.2))
          .id(UUID())
  } else {
      Text("No signature yet")
          .background(Color.gray.opacity(0.2))
          .frame(width: 300, height: 200)
  }

But it does not show the Last Drawing. So if I draw 2 strokes, it only shows the first one. If I draw 3 lines, it only shows the first two. So it always does NOT show the last one.

SignatureCaptureView.swift:

import SwiftUI
import SwiftSignatureView


struct SignatureCaptureView: UIViewRepresentable {
    @Binding var signatureImage: UIImage?
    private var signatureView: SwiftSignatureView // Diese Eigenschaft hinzufügen
    var coordinator: Coordinator? // Füge ein Coordinator-Objekt hinzu

    func getCroppedSignature(from view: SwiftSignatureView) -> UIImage? {
        return view.getCroppedSignature()
    }

    init(signatureImage: Binding<UIImage?>) {
        self._signatureImage = signatureImage
        self.signatureView = SwiftSignatureView()
    }
    func makeUIView(context: Context) -> SwiftSignatureView {
        let signatureView = SwiftSignatureView()
        signatureView.delegate = context.coordinator
        return signatureView
    }

    func updateUIView(_ uiView: SwiftSignatureView, context: Context) {
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, SwiftSignatureViewDelegate {
        var parent: SignatureCaptureView
        var signatureView: PencilKitSignatureView? // Speichere die SignatureView


        init(_ parent: SignatureCaptureView) {
            self.parent = parent
        }

        
        func updateUIView(_ view: ISignatureView) {
            if let signatureView = view as? PencilKitSignatureView {
                parent.signatureImage = signatureView.signature
                view.signature = signatureView.signature
            }
            
        }

        func swiftSignatureViewDidDrawGesture(_ view: ISignatureView, _ tap: UIGestureRecognizer) {
            //print("triggered: DrawGesture")
            if let signatureView = view as? PencilKitSignatureView {
                //parent.signatureImage = signatureView.signature
            }
        }

        func swiftSignatureViewDidDraw(_ view: ISignatureView) {
            print("triggered: DidDraw")
            if let signatureView = view as? PencilKitSignatureView {
                print("saving...")
               parent.signatureImage = signatureView.signature
            } else {
                print("View konnte nicht zu PencilKitSignatureView gecastet werden")
            }
        }
    }
}

Black screen on touch

Hi, I am getting a black screen when I touch in the component, the code is very simple like below:

class FooViewController: UIViewController {

  private lazy var signatureView: SwiftSignatureView = {
    let signatureView: SwiftSignatureView = SwiftSignatureView()
//    signatureView.translatesAutoresizingMaskIntoConstraints = false //Used for constraints, same problem
    return signatureView
  }()

  override func loadView() {
    super.loadView()
    view.addSubview(signatureView)
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    self.signatureView.frame = self.view.frame //The same happens with contraints
  }

}

Background color is not changing from white

Hi,

I've been using SwiftSignatureView for a few months now and everything has been great. Recently, I've been working on a revamp of my application and when I go to use SwiftSignatureView, the background color is not changing to whatever I set it to (in the IB).

I've even tried changing the settings of the SwiftSignatureView (view) programmatically and it still doesn't hold.

Using XCode 12.1 and iOS 13.4 (also tried iOS 14.1). Let me know if anyone has any ideas why this is..

Thank you!

delegate method for ending pan

Shouldn't swiftSignatureViewDidPanInside be rather called when the pan gesture ended? If it's meaned this way - you could you add a swiftSignatureViewDidFinishPanInside when the pan.state == .ended.

Self.bounds in SwiftSignatureView can be non-integral

In the case that your bounds have a fractional dimension, for example a height of 480.5 -- perfectly valid in terms of pixels under a 2x scale factor, your image will become corrupted -- it will shift upward and become fuzzier as the user pans. This was the issue I was having after using a view that was laid out in a storyboard.

You can fix this in one of two ways:

  1. On line 82 and 105 of SwiftSignatureView change
    let rect = self.bounds
    to
    let rect = CGRectIntegral(self.bounds)

Or, make your image context take scale factor into consideration and change lines 83 and 106 to
UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale)

Signature duplicates

In ipad split screens, the signature redraws at diff location once the size is changed from Regular screen to portrait.

POD Not working with Xcode Version 11.3.1

I have Xcode version 11.3.1 and cocoapods version 1.5.3.

I am trying to install SwiftSignatureView with pods. But it installing 1.0.3 version of the library. I have tried this library with my another machine for POC two days before which has Xcode version 10.2.1 and cocoapods version 1.5.3, it works fine and installs the latest version of the library.

Please help me as early as possible.

Change Color to White for iOS Dark Mode

As it stands, the signature still appears black when the app is in dark mode. Understandably, iOS 13 is not out yet but this might be something to consider to change the pen color when using dark mode.

SwiftUI Version

Can you make a SwiftUI version or an example of how to use in a SwiftUI based app please?

Thank you for making an awesome package!

delegates are not working

• After new update delegates are not working for iOS 13
• Also even after calling clear() signature image won't be nil, So how to check sign is blank?

All functionality of my app broken due to new instance for iOS13 in new PencilKitSignatureView.
Is there any workaround to use LegacySwiftSignatureView, might that solve the above 2 issue

Issue when dark Mode 'stroke Color'

this issue happened when dark mode is on.
when the stroke color is setted to white, the exported image color is black, and when the stroke color is setted to black, the exported image color is white.

How to avoid dark mode?

I don't want to support dark mode to my App. Issue is at self.signatureView.getCroppedSignature() this return dark mode supported image with white stroke. Need to support only for light theme with black stroke.
I tried with setting stroke, background color, tint color but didn't work. Please provide solution.

Thanks in advance.

Feature Request

Version 3 brings Pencil kit support which is great but unfortunately completely unsupported on Catalyst and perhaps iPhone apps (didnt test phone). Is there any way to enable a fallback to the old canvas. Presently I am just using v2 until a better solution is found.

signature setter should be open

The signature setter should be open, because sometimes you have to set fill a present signature (back) into the view. Example in my case: A generic backend generated form in a TableView with reusable cells.

Last stroke is not saved in .signature UIImage

You can easily reproduce this if you draw a plus sign with 2 strokes.
If you copy the .signature?.pngData() that is returned in swiftSignatureViewDidDraw and encode it to base64. Put it in any online converter, you will see only the first stroke of your plus sign. E.g - or | instead of +.

Any ideas?

iOS 17

Setting UIImage to signature not works.

I am using SwiftSignatureView in collectionview. Storing signature(UIImage) in datamodule. On reload setting self.signatureView.signature = dataModel.image not working. On each reload It displaying 2 signature one which I draw, not saved and other one is saved in data model. I should always set self.signatureView.signature = dataModel.image if no draw action perform.

Crash on iOS 15 (simulator)

Hi,

I've observed a crash when running on the iOS 15 simulator version 13.0 (build 970), the version distributed with 13.0 beta 5 (13A5212g).

It is systematic and occurs in PencilKitSignatureView.initialize().
On the call to resetTool(), I get a EXC_BAD_ACCESS (code=1, address=0x0).
I don't understand why and I am investigating.

I attached a simple projet which reproduces the problem. It does work on older versions of iOS.
EssaiSignature.zip

Swift 3.0 Support

Hi there,

thanks for keeping it up to date with swift 2.3 but
will there be a swift 3.0 branch in the near future?
Most of the other pods are changing to 3.0 which makes your lib unuseable.

cheers,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.