{"id":655,"date":"2023-05-29T14:39:27","date_gmt":"2023-05-29T06:39:27","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=655"},"modified":"2023-05-29T14:39:27","modified_gmt":"2023-05-29T06:39:27","slug":"%e5%9c%a8ios%e4%b8%8a%e7%bb%98%e5%88%b6%e8%87%aa%e7%84%b6%e7%9a%84%e7%ad%be%e5%90%8d%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/655\/","title":{"rendered":"\u5728ios\u4e0a\u7ed8\u5236\u81ea\u7136\u7684\u7b7e\u540d\u600e\u4e48\u5b9e\u73b0\uff1f"},"content":{"rendered":"

\u5728iOS\u4e0a\u7ed8\u5236\u81ea\u7136\u7684\u7b7e\u540d\u662f\u4e00\u9879\u975e\u5e38\u6709\u8da3\u7684\u4efb\u52a1\uff0c\u56e0\u4e3a\u8fd9\u9700\u8981\u6211\u4eec\u5229\u7528\u89e6\u6478\u4e8b\u4ef6\u548c\u753b\u5e03\u6280\u672f\u6765\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Swift\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7b7e\u540d\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u7b7e\u540d\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u662f\u5c06\u89e6\u6478\u4e8b\u4ef6\u8f6c\u6362\u4e3a\u7ebf\u6bb5\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u7ebf\u6bb5\u7ed8\u5236\u5728\u753b\u5e03\u4e0a\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528UIBezierPath\u5bf9\u8c61\u6765\u7ed8\u5236\u7ebf\u6bb5\uff0c\u5e76\u5728UIView\u5b50\u7c7b\u4e2d\u5b9e\u73b0\u89e6\u6478\u4e8b\u4ef6\u7684\u5904\u7406\u7a0b\u5e8f\u6765\u6355\u83b7\u7528\u6237\u7684\u624b\u52bf\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cSignatureView\u201d\u7684UIView\u5b50\u7c7b\uff0c\u8be5\u7c7b\u5c06\u8d1f\u8d23\u7ed8\u5236\u7b7e\u540d\u3002\u6211\u4eec\u5c06\u5728\u8fd9\u4e2a\u7c7b\u4e2d\u6dfb\u52a0\u4e00\u4e2aUIBezierPath\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u6211\u4eec\u53ef\u4ee5\u8ddf\u8e2a\u7528\u6237\u7684\u624b\u52bf\u8f68\u8ff9\u3002\u6211\u4eec\u8fd8\u5c06\u6dfb\u52a0\u4e00\u4e2a\u6355\u83b7\u89e6\u6478\u4e8b\u4ef6\u7684\u5904\u7406\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u529f\u80fd\u7684\u4ee3\u7801\uff1a<\/p>\n

“`swift<\/p>\n

import UIKit<\/p>\n

class SignatureView: UIView {<\/p>\n<\/p>\n

var path = UIBezierPath()<\/p>\n<\/p>\n

override func touchesBegan(_ touches: Set, with event: UIEvent?) {<\/p>\n

if let touch = touches.first {<\/p>\n

let location = touch.location(in: self)<\/p>\n

path.move(to: location)<\/p>\n

}<\/p>\n

}<\/p>\n<\/p>\n

override func touchesMoved(_ touches: Set, with event: UIEvent?) {<\/p>\n

if let touch = touches.first {<\/p>\n

let location = touch.location(in: self)<\/p>\n

path.addLine(to: location)<\/p>\n

self.setNeedsDisplay()<\/p>\n

}<\/p>\n

}<\/p>\n<\/p>\n

override func draw(_ rect: CGRect) {<\/p>\n

UIColor.black.setStroke()<\/p>\n

path.stroke()<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201cpath\u201d\u7684UIBezierPath\u5bf9\u8c61\uff0c\u5e76\u5728\u201ctouchesBegan\u201d\u65b9\u6cd5\u4e2d\u5c06\u5176\u79fb\u52a8\u5230\u89e6\u6478\u4f4d\u7f6e\u3002\u5728\u201ctouchesMoved\u201d\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u5c06\u7ebf\u6bb5\u6dfb\u52a0\u5230\u8def\u5f84\u4e2d\uff0c\u5e76\u8c03\u7528\u201csetNeeds\u82f9\u679c\u8bc1\u4e66\u5b89\u88c5\u4e0d\u4e86<\/a>Display\u201d\u65b9\u6cd5\u6765\u8bf7\u6c42\u89c6\u56fe\u91cd\u65b0\u7ed8\u5236\u3002\u5728\u201cdraw\u201d\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u9ed1\u8272\u7b14\u5237\u7ed8\u5236\u8def\u5f84\u3002<\/p>\n

\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u4ee5\u6355\u83b7\u7528\u6237\u8f93\u5165\u7684\u89c6\u56fe\uff0c\u8ba9\u6211\u4eec\u5c06\u5176\u6dfb\u52a0\u5230\u89c6\u56fe\u63a7\u5236\u5668\u4e2d\u3002\u5728\u6211\u4eec\u7684\u89c6\u56fe\u63a7\u5236\u5668\u4e2d\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u4e00\u4e2aSignatureView\u5bf9\u8c61\uff0c\u5e76\u5728\u5176\u4e0b\u65b9\u6dfb\u52a0\u4e00\u4e2a\u201cClear\u201d\u6309\u94ae\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u6e05\u9664\u7b7e\u540d\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u529f\u80fd\u7684\u4ee3\u7801\uff1a<\/p>\n

“`swift<\/p>\n

import UIKit<\/p>\n

class ViewController: UIViewController {<\/p>\n<\/p>\n

var signatureView: SignatureView!<\/p>\n<\/p>\n

override func viewDidLoad() {<\/p>\n

super.viewDidLoad()<\/p>\n<\/p>\n

signatureView = SignatureView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height – 50))<\/p>\n

self.view.addSubview(signatureView)<\/p>\n<\/p>\n

let clearButton = UIButton(frame: CGRect(x: 0, y: self.view.frame.height – 50, width: self.view.frame.width, height: 50))<\/p>\n

clearButton.setTitle(“Clear”, for: .normal)<\/p>\n

clearButton.setTitleColor(UIColor.black, for: .normal)<\/p>\n

clearButton.addTarget(self, action: #selector(clearSignature), for: .touchUpInside)<\/p>\n

self.view.addSubview(clearButton)<\/p>\n

}<\/p>\n<\/p>\n

@objc func clearSignature() {<\/p>\n

signatureView.path.re\u82f9\u679ctf\u7b7e\u540d\u4e0a\u67b6<\/a>moveAllPoints()<\/p>\n

signatureView.setNeedsDisplay()<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201csignatureView\u201d\u7684SignatureView\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u89c6\u56fe\u63a7\u5236\u5668\u7684\u89c6\u56fe\u4e2d\u3002\u6211\u4eec\u8fd8\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201cclearButton\u201d\u7684UIButton\u5bf9\u8c61\uff0c\u5e76\u5728\u5176\u4e0a\u65b9\u6dfb\u52a0\u4e00\u4e2a\u201cClear\u201d\u6807\u7b7e\u3002\u6211\u4eec\u4f7f\u7528\u201caddTarget\u201d\u65b9\u6cd5\u5c06\u6e05\u9664\u7b7e\u540d\u7684\u65b9\u6cd5\u201cclearSignature\u201d\u8fde\u63a5\u5230\u6309\u94ae\u7684\u89e6\u6478\u4e8b\u4ef6\u4e2d\u3002<\/p>\n

\u5728\u201cclearSign<\/p>\n

<\/figure>\n<\/p>\n

ature\u201d\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u7b80\u5355\u5730\u5c06\u8def\u5f84\u4e2d\u7684\u6240\u6709\u70b9\u5220\u9664\uff0c\u5e76\u8c03\u7528\u201csetNeedsDisplay\u201d\u65b9\u6cd5\u6765\u8bf7\u6c42\u89c6\u56fe\u91cd\u65b0\u7ed8\u5236\u3002<\/p>\n

\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u5b9e\u73b0\u4e86\u4e00\u4e2a\u53ef\u4ee5\u7ed8\u5236\u81ea\u7136\u7684\u7b7e\u540d\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5f53\u7528\u6237\u5728SignatureView\u4e0a\u7ed8\u5236\u65f6\uff0c\u4ed6\u4eec\u5c06\u770b\u5230\u4e00\u4e2a\u975e\u5e38\u81ea\u7136\u7684\u7b7e\u540d\u6548\u679c\u3002\u5982\u679c\u7528\u6237\u60f3\u8981\u6e05\u9664\u7b7e\u540d\uff0c\u4ed6\u4eec\u53ea\u9700\u70b9\u51fb\u4e0b\u65b9\u7684\u201cClear\u201d\u6309\u94ae\u5373\u53ef\u3002<\/p>\n

\u603b\u7ed3\uff1a<\/p>\n

\u5728iOS\u4e0a\u7ed8\u5236\u81ea\u7136\u7684\u7b7e\u540d\u9700\u8981\u4f7f\u7528\u89e6\u6478\u4e8b\u4ef6\u548c\u753b\u5e03\u6280\u672f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528UIBezierPath\u5bf9\u8c61\u6765\u7ed8\u5236\u7ebf\u6bb5\uff0c\u5e76\u5728UIView\u5b50\u7c7b\u4e2d\u5b9e\u73b0\u89e6\u6478\u4e8b\u4ef6\u7684\u5904\u7406\u7a0b\u5e8f\u6765\u6355\u83b7\u7528\u6237\u7684\u624b\u52bf\u3002\u5728\u89c6\u56fe\u63a7\u5236\u5668\u4e2d\uff0c\u6211\u4eec\u5c06SignatureView\u5bf9\u8c61\u6dfb\u52a0\u5230\u89c6\u56fe\u4e2d\uff0c\u5e76\u6dfb\u52a0\u4e00\u4e2a\u201cClear\u201d\u6309\u94ae\u4ee5\u6e05\u9664\u7b7e\u540d\u3002<\/p>\n

\u4e00\u95e8APP\u8bc1\u4e66\u5236\u4f5c\u5de5\u5177(https:\/\/platform.yimenapp.com\/)\u63d0\u4f9bAPP\u8bc1\u4e66\u5728\u7ebf\u5236\u4f5c\uff0c\u652f\u6301\u82f9\u679c\u8bc1\u4e66\u3001\u5b89\u5353\u8bc1\u4e66\u5728\u7ebf\u4e00\u952e\u5feb\u6377\u5236\u4f5c\u3002\u5de5\u5177\u5b8c\u5168\u514d\u8d39\uff0c\u6ce8\u518c\u6210\u4e3a\u4e00\u95e8APP\u5f00\u53d1\u8005\u5373\u53ef\u4f7f\u7528\uff0c\u5168\u4e2d\u6587\u5316\u4e91\u7aefAPP\u8bc1\u4e66\u5de5\u5177\u3002
\n\u4e00\u952e\u5236\u4f5cIOS\u82f9\u679c\u8bc1\u4e66\uff0c\u5305\u542bappstore\u4e0a\u67b6\u8bc1\u4e66\u3001\u5f00\u53d1\u73af\u5883\u6d4b\u8bd5\u8bc1\u4e66\u3001ADhoc\u751f\u4ea7\u73af\u5883\u6d4b\u8bd5\u8bc1\u4e66\u3001\u5728\u7ebf\u751f\u6210P12\u5f00\u53d1\u8005\u8bc1\u4e66\u8bc1\u4e66\uff0cP12\u63a8\u9001\u8bc1\u4e66\u3001P8\u63a8\u9001\u8bc1\u4e66\uff0c\u5feb\u6377\u7ed1\u5b9aUDID\u3001\u81ea\u5b9a\u4e49\u5305\u540dBundle ID\u3001\u5728\u7ebf\u83b7\u53d6\u63cf\u8ff0\u6587\u4ef6\uff1b
\n\u4e00\u952e\u5236\u4f5c\u5b89\u5353\u8bc1\u4e66\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u5b89\u5353\u5305\u540d\u3001\u7b7e\u540d\u6587\u4ef6\u5bc6\u7801(storepass)\u3001\u522b\u540d(alias)\u3001\u522b\u540d\u5bc6\u7801(keypass)\u3001\u516c\u53f8\/\u673a\u6784\u540d\u79f0 (O)\u3001\u90e8\u95e8 (OU)\u3001\u56fd\u5bb6\/\u5730\u533a (C)\u3001\u7701\u4efd (ST)\u3001\u57ce\u5e02 (L)\u3001\u90ae\u7bb1 (E)\u3001\u4ee5\u53ca\u5b89\u5353\u8bc1\u4e66\u6709\u6548\u671f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728iOS\u4e0a\u7ed8\u5236\u81ea\u7136\u7684\u7b7e\u540d\u662f\u4e00\u9879\u975e\u5e38\u6709\u8da3\u7684\u4efb\u52a1\uff0c\u56e0\u4e3a\u8fd9\u9700\u8981\u6211\u4eec\u5229\u7528\u89e6\u6478\u4e8b\u4ef6\u548c\u753b\u5e03\u6280\u672f\u6765\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Swift\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7b7e\u540d\u5e94\u7528\u7a0b\u5e8f\u3002\u7b7e\u540d\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u662f\u5c06\u89e6\u6478\u4e8b\u4ef6<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1523,1521,1524,1522,1520],"class_list":["post-655","post","type-post","status-publish","format-standard","hentry","category-appzhengshu","tag-iosapp","tag-ios","tag-1524","tag-1522","tag-1520"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=655"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/655\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}