gpt4 book ai didi

ios - 从 SwiftUI View 呈现 UIActivityViewController

转载 作者:行者123 更新时间:2023-12-01 10:33:02 25 4
gpt4 key购买 nike

我正在尝试展示 UIActivityViewController (共享表)来自 SwiftUI View 。我创建了一个名为 ShareSheet 的 View 符合 UIViewControllerRepresentable配置UIActivityViewController ,但事实证明,实际呈现这一点并不容易。

struct ShareSheet: UIViewControllerRepresentable {
typealias UIViewControllerType = UIActivityViewController

var sharing: [Any]

func makeUIViewController(context: UIViewControllerRepresentableContext<ShareSheet>) -> UIActivityViewController {
UIActivityViewController(activityItems: sharing, applicationActivities: nil)
}

func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ShareSheet>) {

}
}

通过 .sheet 天真地这样做导致以下。
.sheet(isPresented: $showShareSheet) {
ShareSheet(sharing: [URL(string: "https://example.com")!])
}

screenshot of failed controller presentation

有没有办法像通常呈现的那样呈现这个?就像覆盖一半屏幕一样?

最佳答案

希望对你有帮助,

struct ShareSheetView: View {
var body: some View {
Button(action: actionSheet) {
Image(systemName: "square.and.arrow.up")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 36, height: 36)
}
}

func actionSheet() {
guard let data = URL(string: "https://www.apple.com") else { return }
let av = UIActivityViewController(activityItems: [data], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}
}
enter image description here

关于ios - 从 SwiftUI View 呈现 UIActivityViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58286344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com