ntr*_*pin 10
UIView
's 和UIViewController
's 可以通过它们各自的类在 SwiftUI 中实现,UIViewRepresentable
而UIViewControllerRepresentable
.
Apple 的 SwiftUI 教程对此进行了讨论,以及将 UIKit 集成到 SwiftUI 的其他方法。
SwiftUI 教程:https : //developer.apple.com/tutorials/swiftui/tutorials
使用 UIViewRepresentable 将 UIView 放入 SwiftUI:https : //developer.apple.com/tutorials/swiftui/creating-and-combining-views ^ 见第 5 节,其中使用 MKMapView 作为 UIView
与 UIKit 交互:https : //developer.apple.com/tutorials/swiftui/interface-with-uikit
很抱歉我的答案中缺少代码,我现在是 AFK。然而,最好的学习方法是自己追踪并解决问题。希望这可以帮助!
更新
如果您想将 SwiftUI 集成到现有的 UIKit 应用程序中,请考虑使用 UIHostingController。它的工作原理如下:
UIHostingController(rootView: MySwiftUIStruct())
Run Code Online (Sandbox Code Playgroud)
https://developer.apple.com/documentation/swiftui/uihostingcontroller
它允许您在 UIKit 应用程序中放置 SwiftUI 内容,就像在其中放置 UIView 或 UIViewController 一样。
归档时间: |
|
查看次数: |
11490 次 |
最近记录: |