我使用UIActivityViewController来允许我的SwiftUI应用程序与其他Activity共享内容:
import Foundation
import SwiftUI
struct ShareSheet : UIViewControllerRepresentable{
var items: [Any]
func makeUIViewController(context: Context) -> UIActivityViewController {
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
return ac
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {
}
}
为了清楚起见,我将使用下面的简单代码:
import SwiftUI
struct ContentView: View {
@State var showForImageShare: Bool = false
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
.onTapGesture {
showForImageShare.toggle()
}
}
.sheet(isPresented: $showForImageShare){
let image = "Hello everybody"
ShareSheet(items: [image])
}
}
}
我在控制台中收到以下警告:
2022-10-23 23:41:07.692216+0300 Test UIActivityViewController[92164:30374157] [LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UICollectionReusableView that is managed by a UICollectionView is not supported, and will result in incorrect self-sizing. View: <_UIActivityContentFooterView: 0x15cd56340; baseClass = UICollectionReusableView; frame = (16 244.333; 361 52); layer = <CALayer: 0x600001ab8180>>
我使用Xcode 14,部署目标:16.0
您能帮我找到展示UIActivityViewController的最佳方式吗?
1条答案
按热度按时间vdzxcuhz1#
这样如何?