I recently created a new SwiftUI project using the beta for Xcode 12. Then I tried to open this project in the non-beta Xcode 11, and after updating the code to use a SwiftUI 1.0-style AppDelegate, I was able to build and run the app. The issue is that now that I have moved to Xcode 11, the app renders inside of a small frame instead of taking up the whole screen.
Here is a simplified example:
Xcode 12 vs. Xcode 11
My simplified view's code is as follows:
struct ContentView: View {
var body: some View {
VStack {
Text("Hello World!")
}
}
}
AppDelegate:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}
SceneDelegate:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
I have tried creating a new Xcode 11 project (which renders properly) and comparing its contents to my own project's, but so far I have not been able to find any difference between its AppDelegate, SceneDelegate, ContentView, build settings, etc.
Is there an option that should be changed in order to have SwiftUI render full-screen in the Xcode 11 project?
First, using some View is important for performance: SwiftUI needs to be able to look at the views we are showing and understand how they change, so it can correctly update the user interface.
SwiftUI gives us equivalents to UIKit's viewDidAppear() and viewDidDisappear() in the form of onAppear() and onDisappear() . You can attach any code to these two events that you want, and SwiftUI will execute them when they occur.
This is caused because the Xcode 11 project is missing a Launch Screen.
This can be resolved by doing the following:
Right click on your project's name, choose New File…, and select Storyboard.
In the storyboard, add a new View Controller.
In your app target's settings, find the "App Icons and Launch Images" section.
Select your launch screen from the dropdown:
Now run your application and the SwiftUI view will fill up the whole screen!
Simply adding
<key>UILaunchScreen</key>
<dict/>
Into the info plist solved this for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With