TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SwiftUI View Alignment Issue on Device Orientation Change and App Background to Foreground Transition

Forums > SwiftUI

I'm encountering an issue with SwiftUI view alignment when the device orientation changes or when the app transitions from the background to the foreground. Despite my efforts, the views(Tabbar) seem to be misaligned, causing a poor user experience.

Below is a simplified version of the code I'm using to display the UI:

@main
struct SSWIFTUIApp: App {

    init() {
        let app = UITabBarAppearance(idiom: .unspecified)
        app.configureWithOpaqueBackground()
        app.backgroundColor = UIColor.systemPink
        app.selectionIndicatorTintColor = .black

        UITabBar.appearance().standardAppearance = app
        if #available(iOS 15.0, *) {
            UITabBar.appearance().scrollEdgeAppearance = app
        }
        UITabBar.appearance().tintColor = .white
        UITabBar.appearance().unselectedItemTintColor = .white
    }

    var body: some Scene {
        WindowGroup {
            TabbarView()
        }
    }
}

struct TabbarView: View {

    @State private var selected: Int = 1

    @State private var id: String = ""

    var body: some View {
        TabView(selection: $selected,
                content:  {
            NavigationView(content: {
                VStack(alignment: .center, spacing: 0, content: {
                    TextField("Connection ID", text: $id)
                        .padding(.horizontal, 5)
                        .frame(height: 40)
                        .border(Color.black, width: 1)
                        .padding()
                })
            })
            .ignoresSafeArea(.keyboard)
            .navigationViewStyle(.stack)
            .tabItem {
                Label("Home", systemImage: "house")
                    .foregroundColor(selected == 1 ? Color.accentColor : Color.white)
            }
            .tag(1)

            NavigationView(content: {
                // Your Settings View Content
            })
            .navigationViewStyle(.stack)
            .tabItem {
                Label("Settings", systemImage: "gear")
                    .foregroundColor(selected == 2 ? Color.accentColor : Color.white)
            }
            .tag(2)
        })
    }
}

Issues demoed below with the above code

   

To decrypt AES 128 in Swift, you can follow these steps:

Import the necessary libraries: Import the CommonCrypto framework into your Swift project.

Create a function for decryption: Write a function that takes the encrypted data and the encryption key as parameters

Set up the decryption context: Initialize a decryption context using the CCCrypt function from the CommonCrypto framework. Provide the appropriate parameters such as algorithm, key, initialization vector (if applicable), and mode.

Perform decryption: Use the CCCrypt function to decrypt the encrypted data.

   

@Chris6677 May be your response is invalid to my question.

   

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.