用Swift显示签名视图

时间:2018-06-19 07:21:39

标签: swift uiviewcontroller sign

嗨,大家好我试图在我的应用程序中以可编程swift实现YPDrwanSignatureView!为此,我使用下面的代码,但是当我运行代码时,我收到此错误,我该如何解决?

错误:

 0x10cdbf267 <+519>: movq   %r10, -0xc8(%rbp)
    0x10cdbf26e <+526>: movq   %r11, -0xd0(%rbp)
    0x10cdbf275 <+533>: callq  0x10ce0995e               ; symbol stub for: Swift._fatalErrorMessage(Swift.StaticString, Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
    0x10cdbf27a <+538>: movq   -0xb0(%rbp), %rax
    0x10cdbf281 <+545>: movq   0x684f8(%rip), %rsi       ; "addSubview:"

Github项目: https://github.com/GJNilsen/YPDrawSignatureView

Swift代码:

import UIKit

class FirmaViewController: UIViewController, YPSignatureDelegate {

    // Connect this Outlet to the Signature View
    @IBOutlet weak var signatureView: YPDrawSignatureView!

    /*required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }*/

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        // Setting this view controller as the signature view delegate, so the didStart() and
        // didFinish() methods below in the delegate section are called.
       // signatureView.delegate = self
       self.view.addSubview(signatureView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

// Function for clearing the content of signature view
/*@IBAction func clearSignature(_ sender: UIButton) {
    // This is how the signature gets cleared
    self.signatureView.clear()
}

// Function for saving signature
@IBAction func saveSignature(_ sender: UIButton) {
    if let signatureImage = self.signatureView.getSignature(scale: 10) {

        UIImageWriteToSavedPhotosAlbum(signatureImage, nil, nil, nil)
        self.signatureView.clear()
    }
}*/

func didStart() {
    print("Started Drawing")
}

func didFinish() {
    print("Finished Drawing")
}

}

1 个答案:

答案 0 :(得分:2)

如果您在情节提要中创建了YPDrawSignatureView,并为其创建了IBOutlet,则您的YPDrawSignatureView已添加到viewController中。
您无需致电self.view.addSubview(signatureView)