swiftuiviewcontroller

someone help or explain why the view looks like this and it doesnt take me to the new view controller


this is the initial view when i click the button it will bring up the next view

this view should be the entire screen legth i dont know whats its doing or what this is called to beable to fix this

import UIKit

class Onboarding_Screen_One: UIViewController {


    @IBOutlet weak var First_button: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBAction func Button_Tapped(_ sender: UIButton) {
        print("Next button tapped on OnBoarding_Screen_One.")
        
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
           if let onboardingScreenTwoVC = storyboard.instantiateViewController(withIdentifier: "Onboarding_Screen_Two") as? Onboarding_Screen_Two {
               self.present(onboardingScreenTwoVC, animated: true, completion: nil)
           }
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

Can someone help or explain why the view looks like this and it doesn't take me to the new view controller?

I've googled and used AI to get this far but the view just isn't deploying right


Solution

  • Since you are presenting a view controller, there's a property called modalPresentationStyle which let you configure how it's going to be presented.

    The default behaviour is what you are seeing.

    If you want it to take the whole screen use this code below:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if let onboardingScreenTwoVC = storyboard.instantiateViewController(withIdentifier: "Onboarding_Screen_Two") as? Onboarding_Screen_Two {
            onboardingScreenTwoVC.modalPresentationStyle = .fullScreen
            self.present(onboardingScreenTwoVC, animated: true, completion: nil)
        }