I am encountering a difficulty with SwiftUI view alignment when the system orientation adjustments or when the app transitions from the background to the foreground. Regardless of my efforts, the views(Tabbar) appear to be misaligned, inflicting a poor consumer expertise.
Under is a simplified model of the code I am utilizing to show the UI:
@important
struct SSWIFTUIApp: App {
var physique: some Scene {
WindowGroup {
TabbarViewApp()
}
}
}
struct TabbarViewApp: View {
init() {
let app = UITabBarAppearance()
app.configureWithOpaqueBackground()
app.backgroundColor = UIColor.systemPink
app.selectionIndicatorTintColor = .black
UITabBar.look().standardAppearance = app
if #out there(iOS 15.0, *) {
UITabBar.look().scrollEdgeAppearance = app
}
}
@State non-public var chosen: Int = 1
@State non-public var id: String = ""
var physique: some View {
TabView(choice: $chosen,
content material: {
NavigationView(content material: {
VStack(alignment: .heart, spacing: 0, content material: {
TextField("Connection ID", textual content: $id)
.padding(.horizontal, 5)
.body(peak: 40)
.border(Shade.black, width: 1)
.padding()
})
})
.navigationViewStyle(.stack)
.tabItem {
Label("Dwelling", systemImage: "home")
.foregroundColor(chosen == 1 ? Shade.accentColor : Shade.white)
}
.tag(1)
NavigationView(content material: {
})
.navigationViewStyle(.stack)
.tabItem {
Label("Settings", systemImage: "gear")
.foregroundColor(chosen == 2 ? Shade.accentColor : Shade.white)
}
.tag(2)
})
}
}
Points demoed beneath with the above code
Upon system orientation change or transitioning the app from the background to the foreground, the alignment of the views appears to be off. I’ve tried adjusting padding, utilizing GeometryReader, and even incorporating particular structure guides, however the situation persists.
I might vastly recognize any insights or options on how to make sure correct alignment of SwiftUI views underneath these circumstances. Thanks upfront on your help!