{"id":1545,"date":"2021-01-27T13:55:16","date_gmt":"2021-01-27T05:55:16","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1545"},"modified":"2021-01-27T13:55:16","modified_gmt":"2021-01-27T05:55:16","slug":"swiftui-%e9%80%9a%e8%bf%87%e4%bb%a3%e7%a0%81%e8%ae%be%e5%ae%9a%e6%a8%aa%e5%b1%8f-%e7%ab%96%e5%b1%8f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1545","title":{"rendered":"SwiftUI \u901a\u8fc7\u4ee3\u7801\u8bbe\u5b9a\u6a2a\u5c4f \u7ad6\u5c4f"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">1.\u9996\u5148\u5728Xcode\u5de5\u7a0b\u8bbe\u5b9a\u4e2d\uff0c\u786e\u8ba4\u6a2a\u5c4f\u548c\u7ad6\u5c4f\u90fd\u662f\u6253\u5f00\u7684\u3002<\/h5>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/01\/image-51-1024x492.png\" alt=\"\" class=\"wp-image-1546\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-1024x492.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-300x144.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-768x369.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-830x399.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-230x111.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-350x168.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51-480x231.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/01\/image-51.png 1190w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">2.\u5728AppDelegate\u4e2d\u3002<\/h5>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u5f53\u524d\u754c\u9762\u652f\u6301\u7684\u65b9\u5411\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u53ea\u80fd\u7ad6\u5c4f\uff0c\u4e0d\u80fd\u6a2a\u5c4f\u663e\u793a\uff09\n    var interfaceOrientations:UIInterfaceOrientationMask = .portrait{\n        didSet{\n            \/\/\u5f3a\u5236\u8bbe\u7f6e\u6210\u7ad6\u5c4f\n            if interfaceOrientations == .portrait{\n                UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue,\n                                          forKey: \"orientation\")\n            }\n            \/\/\u5f3a\u5236\u8bbe\u7f6e\u6210\u6a2a\u5c4f\n            else if !interfaceOrientations.contains(.portrait){\n                UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue,\n                                          forKey: \"orientation\")\n            }\n        }\n    }\n    \/\/\u8fd4\u56de\u5f53\u524d\u754c\u9762\u652f\u6301\u7684\u65cb\u8f6c\u65b9\u5411\n    func application(_ application: UIApplication, supportedInterfaceOrientationsFor\n        window: UIWindow?)-> UIInterfaceOrientationMask {\n        return interfaceOrientations\n    }<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">3.\u5728swiftUI\u7684View\u753b\u9762\u4e2d\uff0c\u53ef\u4ee5\u63a7\u5236\u6a2a\u5c4f\u548c\u7ad6\u5c4f\u5e55\u53d8\u6362\u3002<\/h5>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct XXXXXView: View {\n    \n    var body: some View {\n        ZStack(alignment: .bottom) {\n            xxxxxxx\n            \n        }.frame(alignment: .bottom)\n        .onAppear() {\n            let appDelegate = UIApplication.shared.delegate as! AppDelegate\n            appDelegate.interfaceOrientations = [.landscapeRight]\n        }.onDisappear() {\n            let appDelegate = UIApplication.shared.delegate as! AppDelegate\n            appDelegate.interfaceOrientations = .portrait\n        }\n   \n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u9996\u5148\u5728Xcode\u5de5\u7a0b\u8bbe\u5b9a\u4e2d\uff0c\u786e\u8ba4\u6a2a\u5c4f\u548c\u7ad6\u5c4f\u90fd\u662f\u6253\u5f00\u7684\u3002 2.\u5728AppDelegate\u4e2d\u3002 3.\u5728swift [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1545"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1545"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1545\/revisions"}],"predecessor-version":[{"id":1548,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1545\/revisions\/1548"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}