{"id":1180,"date":"2020-11-04T16:53:29","date_gmt":"2020-11-04T08:53:29","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1180"},"modified":"2020-11-07T23:24:33","modified_gmt":"2020-11-07T15:24:33","slug":"swiftui%e4%b8%ad-%e5%b1%8f%e5%b9%95%e6%88%aa%e5%9b%be","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1180","title":{"rendered":"SwiftUI\u4e2d \u5c4f\u5e55\u622a\u56fe"},"content":{"rendered":"\n<ul><li>SceneDelegate\u4e2d\u5f97\u5230window\u5bf9\u8c61<\/li><\/ul>\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=\"\">import UIKit\nimport SwiftUI\n\nclass SceneDelegate: UIResponder, UIWindowSceneDelegate {\n\n    var window: UIWindow?\n\n\n    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {\n        \/\/ Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.\n        \/\/ If using a storyboard, the `window` property will automatically be initialized and attached to the scene.\n        \/\/ This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).\n\n        \/\/ Create the SwiftUI view that provides the window contents.\n        let contentView = ContentView()\n\n        \/\/ Use a UIHostingController as window root view controller.\n        if let windowScene = scene as? UIWindowScene {\n            let window = UIWindow(windowScene: windowScene)\n            \/\/\u5b9a\u4e49windowComm\u53d8\u91cf\u4fdd\u5b58window\u5bf9\u8c61\n            windowComm = window\n            window.rootViewController = UIHostingController(rootView: contentView)\n            self.window = window\n            \n            window.makeKeyAndVisible()\n        }\n    }<\/pre>\n\n\n\n<ul><li>SwiftUI\u4e2d\u8c03\u7528\u7684\u4f8b\u5b50<\/li><\/ul>\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 xxxxelView: View {\n    var isTakeSnapPhoto = NotificationCenter.default.publisher(for: .takeSnapPhoto)\n    var body: some View {\n        VStack(spacing: 0) {\n          \n        }.onReceive(isTakeSnapPhoto) { _ in\n  \n            let screenRect = UIScreen.main.bounds\n                UIGraphicsBeginImageContext(screenRect.size)\n                let ctx: CGContext = UIGraphicsGetCurrentContext()!\n                windowComm!.layer.render(in: ctx)\n                let image = UIGraphicsGetImageFromCurrentImageContext()\n                UIGraphicsEndImageContext();\n        }\n    }\n\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SceneDelegate\u4e2d\u5f97\u5230window\u5bf9\u8c61 SwiftUI\u4e2d\u8c03\u7528\u7684\u4f8b\u5b50<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1180"}],"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=1180"}],"version-history":[{"count":5,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1180\/revisions"}],"predecessor-version":[{"id":1192,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1180\/revisions\/1192"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}