如何解决在 Mac(Catalyst) 上共享菜单屏幕位置
我创建了一个这样的 ShareButton:
struct ShareButton<Content: View>: View {
var items: [Any]
var content: () -> Content
var body: some View {
Button {
let avc = UIActivityViewController(activityItems: items,applicationActivities: [])
avc.popoverPresentationController?.sourceView = UIHostingController(rootView: self).view
UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.rootViewController?.present(avc,animated: false)
} label: {
content()
}
}
}
可以这样使用:
ShareButton(items: [someURL]){
Label("share",systemImage:"square.and.arrow.up")
}
但是,在 Mac(Catalyst) 和 iPad 上,共享菜单弹出窗口出现在错误的位置。
似乎 UIHostingController(rootView: self).view
返回了错误的参考视图。有人知道如何解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。