我正在使用 SwiftUI 开发人员列表页面,iPhone X 屏幕足够大,但 iPhone 8 中的标题不在屏幕上:
然而,在 iPhone 8 或更小的屏幕中,“Find People”离左边太近,“Follow All”甚至在屏幕外:

我知道在 UIKit 自动布局中可以很容易地解决这个问题,但我想知道 SwiftUI 解决这个问题的最佳方法或正确方法是什么,有些答案说使用像 Spacer 或 HStack,但它们都没有实际工作。
var body: some View {
NavigationView {
List {
ForEach(people) {person in
PersonView(person: person)
}
}.navigationBarItems(leading:
VStack(spacing: 10) {
HStack(spacing: 100) {
Text("Find People").font(.system(size: 30)).bold()
Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
}
HStack(spacing: 20) {
Text("Import from: ")
ForEach(socialIcons, id: \.self) {icon in
Image(icon).resizable().frame(width: 25, height: 25)
}
}
}
)
}
}
Run Code Online (Sandbox Code Playgroud) 我想摆脱我的函数中的“‘windows’在 iOS 15.0 中已弃用:在相关窗口场景上使用 UIWindowScene.windows”消息(顺便说一下,我的函数运行得很好。)。
涉及的代码行:
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我的职能:
struct AdView : UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView {
let banner = GADBannerView(adSize: kGADAdSizeBanner)
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716" // test ad
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
return banner
}
func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) {}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过,但它不起作用:
banner.rootViewController = UIApplication.shared.connectedScenes.first?.rootViewController
Run Code Online (Sandbox Code Playgroud)
谢谢