{"id":1748,"date":"2023-06-27T14:38:38","date_gmt":"2023-06-27T06:38:38","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=1748"},"modified":"2023-06-27T14:38:38","modified_gmt":"2023-06-27T06:38:38","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8ios%e8%ae%be%e5%a4%87%e4%b8%8a%e6%8d%95%e6%8d%89%e7%94%a8%e6%88%b7%e7%ad%be%e5%90%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/1748\/","title":{"rendered":"\u5982\u4f55\u5728ios\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d?"},"content":{"rendered":"

\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u662f\u4e00\u9879\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u5e94\u7528\u573a\u666f\uff0c\u5982\u7535\u5b50\u7b7e\u540d\u3001\u5408\u540c\u7b7e\u7f72\u7b49\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

1. \u539f\u7406<\/p>\n

\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u7684\u539f\u7406\u662f\u5229\u7528\u89e6\u6478\u4e8b\u4ef6\u6765\u83b7\u53d6\u7528\u6237\u5728\u5c4f\u5e55\u4e0a\u7684\u624b\u5199\u8f68\u8ff9\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u8f68\u8ff9\u8f6c\u5316\u4e3a\u4e00\u5f20\u56fe\u7247\uff0c\u7528\u4e8e\u4fdd\u5b58\u6216\u5c55\u793a\u3002<\/p>\n

\u5177\u4f53\u5b9e\u73b0\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n

1.1 \u521b\u5efa\u4e00\u4e2aUIView\u4f5c\u4e3a\u7b7e\u540d\u533a\u57df\uff0c\u5f53\u7528\u6237\u5728\u8be5\u533a\u57df\u5185\u8fdb\u884c\u624b\u5199\u65f6\uff0c\u89e6\u53d1\u89e6\u6478\u4e8b\u4ef6\u3002<\/p>\n

1.2 \u5728\u89e6\u6478\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u83b7\u53d6\u7528\u6237\u624b\u6307\u5728\u5c4f\u5e55\u4e0a\u7684\u4f4d\u7f6e\uff0c\u5e76\u5c06\u8fd9\u4e9b\u4f4d\u7f6e\u70b9\u8fde\u6210\u4e00\u6761\u7ebf\u6bb5\uff0c\u5f62\u6210\u624b\u5199\u8f68\u8ff9\u3002<\/p>\n

1.3 \u5c06\u624b\u5199\u8f68\u8ff9\u7ed8\u5236\u5230\u4e00\u4e2aUIImage\u5bf9\u8c61\u4e0a\uff0c\u7136\u540e\u5c06\u8be5\u56fe\u7247\u4fdd\u5b58\u6216\u5c55\u793a\u3002<\/p>\n

2. \u8be6\u7ec6\u6b65\u9aa4<\/p>\n

\u4e0b\u9762\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728iOS\u8bbe\u5907\u4e0a\u5b9e\u73b0\u6355\u6349\u7528\u6237\u7b7e\u540d\u7684\u529f\u80fd\uff0c\u5305\u62ec\u521b\u5efa\u7b7e\u540d\u533a\u57df\u3001\u83b7\u53d6\u624b\u5199\u8f68\u8ff9\u3001\u7ed8\u5236\u56fe\u7247\u7b49\u3002<\/p>\n

2.1 \u521b\u5efa\u7b7e\u540d\u533a\u57df<\/p>\n

\u9996\u5148\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2aUIView\u4f5c\u4e3a\u7b7e\u540d\u533a\u57df\uff0c\u7528\u4e8e\u63a5\u6536\u7528\u6237\u624b\u5199\u8f68\u8ff9\u3002\u53ef\u4ee5\u5728Storyboard\u6216\u4ee3\u7801\u4e2d\u521b\u5efa\u8be5\u89c6\u56fe\uff0c\u5e76\u8bbe\u7f6e\u5176\u80cc\u666f\u989c\u8272\u3001\u8fb9\u6846\u7b49\u5c5e\u6027\u3002<\/p>\n

2.2 \u83b7\u53d6\u624b\u5199\u8f68\u8ff9<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u9700\u8981\u5728\u7b7e\u540d\u533a\u57df\u4e2d\u6dfb\u52a0\u89e6\u6478\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570\uff0c\u4ee5\u83b7\u53d6\u7528\u6237\u624b\u5199\u8f68\u8ff9\u3002<\/p>\n

\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u89e6\u6478\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570\uff1a<\/p>\n

“`<\/p>\n

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

guard let touch = touches.first else { return }<\/p>\n

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

}<\/p>\n

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

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

guard let touch = touches.first else { return }<\/p>\n<\/p>\n

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

UIGraphicsBeginImageContext(self.frame.size)<\/p>\n

self.image?.draw(in: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))<\/p>\n

let context = UIGraphicsGetCurrentContext()<\/p>\n

context?.setLineWidth(2.0)<\/p>\n

context?.setStrokeColor(UIColor.black.cgColor)<\/p>\n

context?.move(to: CGPoint(x: lastPoint.x, y: lastPoint.y))<\/p>\n

context?.addLine(to: CGPoint(x: currentPoint.x, y: currentPoint.y))<\/p>\n

context?.strokePath()<\/p>\n<\/p>\n

self.image = UIGraphicsGetImageFromCurrentImageContext()<\/p>\n

UIGraphicsEndImageContext()<\/p>\n<\/p>\n

lastPoint = currentPoint<\/p>\n

}<\/p>\n

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

UIGraphicsBeginImageContext(self.frame.size)<\/p>\n

self.image?.draw(in: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))<\/p>\n

let context = UIGraphicsGetCurrentContext()<\/p>\n

context?.setLineWidth(2.0)<\/p>\n

context?.setStrokeColor(UIColor.black.cgColor)<\/p>\n

context?.move(to: CGPoint(x: lastPoint.x, y: lastPoint.y))<\/p>\n

context?.addLine(to: CGPoint(x: lastPoint.x, y: lastPoint.y))<\/p>\n

context?.strokePath()<\/p>\n<\/p>\n

self.image = UIGraphicsGetImageFromCurrentImageContext()<\/p>\n

UIGraphicsEndImageContext()<\/p>\n

}<\/p>\n

“`<\/p>\n

\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0ctouchesBegan\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u624b\u6307\u5728\u5c4f\u5e55\u4e0a\u7684\u8d77\u59cb\u4f4d\u7f6e\uff1btouchesMoved\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u624b\u6307\u5728\u5c4f\u5e55\u4e0a\u79fb\u52a8\u7684\u4f4d\u7f6e\uff0c\u5e76\u5c06\u8fd9\u4e9b\u4f4d\u7f6e\u70b9\u8fde\u6210\u4e00\u6761\u7ebf\u6bb5\uff1btouchesEnded\u51fd\u6570\u7528\u4e8e\u7ed3\u675f\u624b\u5199\u64cd\u4f5c\u3002<\/p>\n

\u5728touchesMoved\u51fd\u6570\u4e2d\uff0c\u4f7f\u7528UIGraphicsBeginImageContext\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u56fe\u5f62\u4e0a\u4e0b\u6587\uff0c\u5e76\u5c06\u5f53\u524d\u89c6\u56fe\u7684\u56fe\u82f9\u679c13\u53ef\u4ee5\u8bbe\u7f6e\u7b7e\u540d<\/a>\u50cf\u7ed8\u5236\u5230\u8be5\u4e0a\u4e0b\u6587\u4e2d\u3002\u7136\u540e\uff0c\u4f7f\u7528Core Graphics\u51fd\u6570\u5c06\u624b\u5199\u8f68\u8ff9\u7ed8\u5236\u5230\u56fe\u5f62\u4e0a\u4e0b\u6587\u4e2d\uff0c\u5e76\u5c06\u7ed8\u5236\u597d\u7684\u56fe\u50cf\u4fdd\u5b58\u5230self.image\u5c5e\u6027\u4e2d\u3002\u6700\u540e\uff0c\u4f7f\u7528UIGraphicsEndImageContext\u51fd\u6570\u7ed3\u675f\u56fe\u5f62\u4e0a\u4e0b\u6587\u3002<\/p>\n

2.3 \u7ed8\u5236\u56fe\u7247<\/p>\n

\u6700\u540e\uff0c\u9700\u8981\u5c06\u7528\u6237\u624b\u5199\u8f68\u8ff9\u8f6c\u5316\u4e3a\u4e00\u5f20\u56fe\u7247\uff0c\u5e76\u5c06\u8be5\u56fe\u7247\u4fdd\u5b58\u6216\u5c55\u793a\u3002<\/p>\n

\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5c06self.image\u5c5e\u6027\u8f6c\u5316\u4e3a\u4e00\u5f20UIImage\u5bf9\u8c61\uff1a<\/p>\n

\u82f9\u679c\u5e94\u7528\u7b7e\u540dapp<\/a>`<\/p>\n

let signatureImage = self.signatureView.image<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u53ef\u4ee5\u5c06\u8be5UIImage\u5bf9\u8c61\u4fdd\u5b58\u5230\u672c\u5730\u6216\u5c55\u793a\u5728\u89c6\u56fe\u4e2d\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`<\/p>\n

UIImageWriteToSavedPhotosAlbum(signatureImage!, nil, nil, nil)<\/p>\n

self.imageView.image = signatureImage<\/p>\n

“`<\/p>\n

\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0cUIImageWriteToSavedPhotosAlbum\u51fd\u6570\u7528\u4e8e\u5c06UIImage\u5bf9\u8c61\u4fdd\u5b58\u5230\u76f8\u518c\u4e2d\uff1bself.imageView\u5c5e\u6027\u7528\u4e8e\u5c55\u793a\u8be5UIImage\u5bf9\u8c61\u3002<\/p>\n

3. \u603b\u7ed3<\/p>\n

\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u662f\u4e00\u9879\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u5e94\u7528\u573a\u666f\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728iOS\u8bbe\u5907\u4e0a\u5b9e\u73b0<\/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\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u662f\u4e00\u9879\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u5e94\u7528\u573a\u666f\uff0c\u5982\u7535\u5b50\u7b7e\u540d\u3001\u5408\u540c\u7b7e\u7f72\u7b49\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u30021. \u539f\u7406\u5728iOS\u8bbe\u5907\u4e0a\u6355\u6349\u7528\u6237\u7b7e\u540d\u7684\u539f\u7406\u662f\u5229<\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1919,28,3732,3733,3734],"class_list":["post-1748","post","type-post","status-publish","format-standard","hentry","category-appzhengshu","tag-1919","tag-28","tag-3732","tag-3733","tag-3734"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1748","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\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=1748"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/1748\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=1748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=1748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=1748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}