我如何在孩子们的视图中启动Swiftui应用程序?
@main
struct MemorizableApp: App {
init() {
FirebaseApp.configure() // Configure the FirebaseApp instance
Database.database().isPersistenceEnabled = true // Set DB persistence to true
}
var body: some Scene {
WindowGroup {
if Auth.auth().currentUser == nil {
SignInView()
.onOpenURL{ url in
GIDSignIn.sharedInstance.handle(url)
}
} else {
MainView()
}
}
}
}
这是MemorizableApp.swift
。如您所见,该应用在MainView中启动。但是我希望该应用程序可以在笔记本视图中启动。显然,在上面的代码中将Mainview更改为NotebookSview不起作用,因为1)NotebookSview中没有NavigationView,而2)我将无法导航回MainView。但是,某种程度上,Apple的快捷方式应用程序完全可以做到这一点,而无需创建自定义的返回按钮。我该如何实现这种行为?
Okay, here's what my app looks like.
@main
struct MemorizableApp: App {
init() {
FirebaseApp.configure() // Configure the FirebaseApp instance
Database.database().isPersistenceEnabled = true // Set DB persistence to true
}
var body: some Scene {
WindowGroup {
if Auth.auth().currentUser == nil {
SignInView()
.onOpenURL{ url in
GIDSignIn.sharedInstance.handle(url)
}
} else {
MainView()
}
}
}
}
And this is MemorizableApp.swift
. As you can see, the app starts in MainView. But I want the app to launch in NotebooksView instead. Obviously, changing MainView to NotebooksView in the code above won't work because 1) NotebooksView doesn't have a NavigationView in it, and 2) I won't be able to navigate back to MainView. But somehow Apple's Shortcuts app did exactly this without creating a custom back button. How can I achieve this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是以编程方式激活
navigationLink
:in
mainView
add:@State var showerNavigate = false
,然后修改navigationlink
到以下内容:和
MemorizableApp
:注意:
navigationLink的使用(目标:content:content,isActive:iSACTIVE:绑定< bool>)
&navigationView
是ios 16
中的debected 。看看在这里& 在这里。What you need to do is activate your
NavigationLink
programmatically:In
MainView
add:@State var shouldNavigate = false
, then modify yourNavigationLink
to the following:And in
MemorizableApp
:Note: The use of
NavigationLink(destination: Content, isActive: Binding<Bool>)
&NavigationView
is deprecated iniOS 16
. Take a look here & here.