{"id":21154,"date":"2023-06-24T12:04:29","date_gmt":"2023-06-24T04:04:29","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=21154"},"modified":"2023-06-24T12:04:29","modified_gmt":"2023-06-24T04:04:29","slug":"ios-%e6%82%ac%e6%b5%ae%e6%a1%86%e5%bc%80%e5%8f%91%e6%8e%a8%e8%8d%90%e4%b8%80%e9%97%a8app%e5%bc%80%e5%8f%91%e5%b9%b3%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/21154\/","title":{"rendered":"ios \u60ac\u6d6e\u6846\u5f00\u53d1\u63a8\u8350\u4e00\u95e8APP\u5f00\u53d1\u5e73\u53f0"},"content":{"rendered":"<p>iOS\u60ac\u6d6e\u6846\uff0c\u4e5f\u53eb\u505a\u60ac\u6d6e\u7403\u6216\u8005\u60ac\u6d6e\u6309\u94ae\uff0c\u662f\u6307\u4e00\u4e2a\u80fd\u591f\u5728iOS\u8bbe\u5907\u5c4f\u5e55\u4e0a\u6d6e\u52a8\u7684\u5c0f\u56fe\u6807\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e5%ae%83%e6%9d%a5\/\" title=\"\u5b83\u6765\" target=\"_blank\">\u5b83\u6765<\/a><\/span>\u5b9e\u73b0\u67d0\u4e9b\u64cd\u4f5c\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u7528\u5b83\u6765\u5feb\u901f\u542f\u52a8\u67d0\u4e2a\u5e94\u7528\uff0c\u6216\u8005\u5728\u7f51\u9875\u4e0a\u6dfb\u52a0\u4e66\u7b7e\u7b49\u7b49\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecdiOS\u60ac\u6d6e\u6846\u7684\u5b9e\u73b0\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n<p>\u4e00\u3001\u5b9e\u73b0\u539f\u7406<\/p>\n<p>iOS\u60ac\u6d6e\u6846\u7684\u5b9e\u73b0\u539f\u7406\u4e3b\u8981\u662f\u901a\u8fc7\u5229\u7528\u7cfb\u7edf\u63d0\u4f9b\u7684UIWindow\u548cUIView\u6765\u5b9e\u73b0\u7684\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>1. \u521b\u5efa\u4e00\u4e2aUIWindow<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e5%af%b9%e8%b1%a1\/\" title=\"\u5bf9\u8c61\" target=\"_blank\">\u5bf9\u8c61<\/a><\/span>\uff0c\u5e76\u5c06\u5b83\u7684windowLevel\u5c5e\u6027\u8bbe\u4e3aUIWindowLevelAlert\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u8bc1\u5b83\u5728\u6240\u6709\u5176\u4ed6\u7a97\u53e3\u7684\u5c42\u7ea7\u6700\u9ad8\u3002<\/p>\n<p>2. \u5728UIWindow\u5bf9\u8c61\u4e0a\u6dfb\u52a0\u4e00\u4e2aUIButton\u6216\u8005UIImageView\uff0c\u4f5c\u4e3a\u60ac\u6d6e\u6846\u7684\u56fe\u6807\u3002<\/p>\n<p>3. \u901a\u8fc7\u624b\u52bf\u8bc6\u522b\u6765\u5b9e\u73b0\u60ac\u6d6e\u6846\u7684\u62d6\u62fd\u548c\u70b9\u51fb<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e4%ba%8b%e4%bb%b6\/\" title=\"\u4e8b\u4ef6\" target=\"_blank\">\u4e8b\u4ef6<\/a><\/span>\u3002<\/p>\n<p>\u4e8c\u3001\u8be6\u7ec6\u6b65\u9aa4<\/p>\n<p>1. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Xcode\u5de5\u7a0b\uff0c\u9009\u62e9Single View Application\u6a21\u677f\u3002<\/p>\n<p>2. \u5728Main.storyboard\u4e2d\u62d6\u5165\u4e00\u4e2aUIButton\u6216\u8005UIImageView\uff0c\u4f5c\u4e3a\u60ac\u6d6e\u6846\u7684\u56fe\u6807\u3002\u8bbe\u7f6e\u56fe\u6807\u7684\u5927\u5c0f\u548c\u4f4d\u7f6e\uff0c\u4ee5\u53ca\u76f8\u5e94\u7684\u56fe\u7247\u3002<\/p>\n<p>3. <a href=\"https:\/\/www.yimenapp.net\/dabao-978.html\">URL Schema<\/a>\u5728ViewController.swift\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>class ViewController: UIViewController {<\/p>\n<p>    var window: UIWindow?<\/p>\n<p>    var button: UIButton?<\/p>\n<p>    var lastLocation: CGPoint?<\/p>\n<\/p>\n<p>    override func viewDidLoad() {<\/p>\n<p>        super.viewDidLoad()<\/p>\n<\/p>\n<p>        \/\/ \u521b\u5efaUIWindow\u5bf9\u8c61<\/p>\n<p>        window = UIWindow(frame: CGRect(x: 0, y: 0, width: 60, height: 60))<\/p>\n<p>        window?.windowLevel = UIWindow.Level.alert<\/p>\n<\/p>\n<p>        \/\/ \u521b\u5efaUIButton\u5bf9\u8c61\uff0c\u5e76\u6dfb\u52a0\u5230UIWindow\u4e0a<\/p>\n<p>        button = UIButton(type: .system)<\/p>\n<p>        button?.frame = CGRect(x: 0, y: 0, width: 60, height: 60)<\/p>\n<p>        button?.setBackgroundImage(UIImage(named: &#8220;icon&#8221;), for: .normal)<\/p>\n<p>        button?.addTarget(self, action: #selector(buttonClicked), for: .touchUpInside)<\/p>\n<p>        window?.addSubview(button!)<\/p>\n<\/p>\n<p>        \/\/ \u6dfb\u52a0\u624b\u52bf\u8bc6\u522b\u5668<\/p>\n<p>        let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))<\/p>\n<p>        window?.addGestureRecognizer(panGesture)<\/p>\n<p>    }<\/p>\n<\/p>\n<p>    @objc func buttonClicked() {<\/p>\n<p>        \/\/ \u70b9\u51fb\u4e8b\u4ef6\u5904\u7406<\/p>\n<p>        print(&#8220;button clicked&#8221;)<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/31\/15\/17507816517.jpg\" \/><\/figure><\/p>\n<p>  }<\/p>\n<\/p>\n<p>    @objc func handlePanGesture(_ sender: UIPanGestureRecognizer) {<\/p>\n<p>        \/\/ \u62d6\u62fd\u4e8b\u4ef6\u5904\u7406<\/p>\n<p>        let translation <a href=\"https:\/\/www.yimenapp.net\/dabao-4205.html\">\u82f9\u679cipa\u8f6f\u4ef6\u6e90<\/a>= sender.translation(in: self.view)<\/p>\n<p>        if let view = sender.view {<\/p>\n<p>            view.center = CGPoint(x:view.center.x + translation.x,<\/p>\n<p>                                  y:view.center.y + translation.y)<\/p>\n<p>        }<\/p>\n<p>        sender.setTranslation(CGPoint.zero, in: self.view)<\/p>\n<p>    }<\/p>\n<\/p>\n<p>    override func viewDidAppear(_ animated: Bool) {<\/p>\n<p>        super.viewDidAppear(animated)<\/p>\n<\/p>\n<p>        \/\/ \u663e\u793aUIWindow<\/p>\n<p>        window?.makeKeyAndVisible()<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u8fd0\u884c\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u60ac\u6d6e\u6846\u51fa\u73b0\u5728\u5c4f\u5e55\u4e0a\u3002\u53ef\u4ee5\u901a\u8fc7\u62d6\u62fd\u6765\u6539\u53d8\u5b83\u7684\u4f4d\u7f6e\uff0c\u4e5f\u53ef\u4ee5\u70b9\u51fb\u5b83\u6765\u89e6\u53d1\u76f8\u5e94\u7684\u4e8b\u4ef6\u3002<\/p>\n<p>\u81f3\u6b64\uff0ciOS\u60ac\u6d6e\u6846\u7684\u5f00\u53d1\u5c31\u5b8c\u6210\u4e86\u3002\u5f53\u7136\uff0c\u8fd9\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u53ef\u80fd\u4f1a\u6d89\u53ca\u5230\u66f4\u591a\u7684\u529f\u80fd\u548c\u7ec6\u8282\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS\u60ac\u6d6e\u6846\uff0c\u4e5f\u53eb\u505a\u60ac\u6d6e\u7403\u6216\u8005\u60ac\u6d6e\u6309\u94ae\uff0c\u662f\u6307\u4e00\u4e2a\u80fd\u591f\u5728iOS\u8bbe\u5907\u5c4f\u5e55\u4e0a\u6d6e\u52a8\u7684\u5c0f\u56fe\u6807\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u5b83\u6765\u5b9e\u73b0\u67d0\u4e9b\u64cd\u4f5c\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u7528\u5b83\u6765\u5feb\u901f\u542f\u52a8\u67d0\u4e2a\u5e94\u7528\uff0c\u6216\u8005\u5728\u7f51\u9875\u4e0a\u6dfb\u52a0\u4e66\u7b7e\u7b49\u7b49\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecdiO<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[12133,15829,3876,15830,1974],"special":[],"attr":[],"class_list":["post-21154","post","type-post","status-publish","format-standard","hentry","category-www","tag-android-cordova-","tag-apksapk","tag-3876","tag-15830","tag-1974","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/21154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=21154"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/21154\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=21154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=21154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=21154"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=21154"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=21154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}