我最近使用Xcode 12的beta版创建了一个新的SwiftUI项目。然后我尝试在非beta版的Xcode 11中打开此项目,并更新代码以使用SwiftUI 1.0-style的AppDelegate,我能够构建和运行应用程序。问题是,现在我已经转移到Xcode 11,应用程序在一个小框架内呈现,而不是占据整个屏幕。
以下是一个简化的示例:
Xcode 12 vs. Xcode 11
我尝试创建了一个新的Xcode 11项目(可以正常显示),并将其内容与我自己的项目进行比较,但到目前为止,我还没有找到其AppDelegate、SceneDelegate、ContentView、构建设置等之间的任何区别。是否有选项需要更改才能使SwiftUI在Xcode 11项目中全屏渲染?
以下是一个简化的示例:
Xcode 12 vs. Xcode 11
我的简化视图代码如下:
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)
}
}
场景代理:
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()
}
}
我尝试创建了一个新的Xcode 11项目(可以正常显示),并将其内容与我自己的项目进行比较,但到目前为止,我还没有找到其AppDelegate、SceneDelegate、ContentView、构建设置等之间的任何区别。是否有选项需要更改才能使SwiftUI在Xcode 11项目中全屏渲染?