我在 Kotlin 中使用 org.jetbrains.compose v 1.4.0 进行了最简单的设置
fun MainViewController() =
ComposeUIViewController {
Button(onClick = { }) {
Text("Click me")
}
}
在 iOS 上我有:
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
MainIosKt.MainViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
struct ContentView: View {
@State var showSettings = false
var body: some View {
VStack {
ZStack {
Rectangle()
.fill(.red)
.frame(width: 500, height: 500)
ComposeView()
.padding(EdgeInsets(top: 140, leading: 140, bottom: 140, trailing: 140))
}
}
}
}
即使没有专门设置,也会有白色背景遮挡红色矩形。我想要透明背景,以便我可以将撰写 UI 覆盖在其他 iOS 内容(例如相机提要)上。
尝试:
但是白色背景仍然存在。现在不支持还是我做错了什么?
感谢这个松弛的对话:https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1685005635951389
并更新至 compose-multiplatform 1.5.0 只需从对话中添加两个文件并像这样使用它:
fun MainViewController() =
TransparentComposeUIViewController {
Button(onClick = { }) {
Text("Click me")
}
}