Reputation: 2324
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?
Upvotes: 35
Views: 9498
Reputation: 14362
The solution to this is to add a LaunchScreen entry in Info.plist as follows:
<key>UILaunchScreen</key>
<dict>
<key>UIColorName</key>
<string>LaunchBackground</string>
</dict>
The LaunchBackground must correspond to a color in Assets.xcassets.
Upvotes: 4
Reputation: 3668
Simply adding
<key>UILaunchScreen</key>
<dict/>
Into the info plist solved this for me.
Upvotes: 33
Reputation: 3
@ahimsa das mentioned that
If I type in a random string into the "Launch Screen File" field. It works! Any random gibberish like "osd8nfcosd" and it still works. Bizzare lol.
which is weird but I think it has something to do with the cache on iOS. By typing a random string into the launchscreen file name (in the app's target settings), xcode searches your project for the storyboard file, but since it cant find any, it defaults to a cached image of the launchscreen (correct me if I'm wrong) which would be the image of the very first launchscreen.storyboard
file that was created
(in my case this happened as I was using UIKit and wanted to make an app programmatically so I deleted launchscreen.storyboard
and all references to it, which of course, resulted in a small UIWindowScene
)
Upvotes: 0
Reputation: 2324
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!
Upvotes: 43