简体   繁体   English

SwiftUI:从 NagivationLink 打开全屏视图(即隐藏侧边栏)

[英]SwiftUI: Open a full screen View (i.e. hide SideBar) from a NagivationLink

I've been digging through the apple docs for a way to open a View from a NavigationLink where the SideBar is collapsed by default.我一直在研究苹果文档,寻找一种从 NavigationLink 中打开视图的方法,默认情况下侧边栏是折叠的。

Everything I've tried leaves the side bar visible (but collapsible by pressing the sidebar button).我尝试过的所有内容都使侧边栏可见(但可以通过按侧边栏按钮折叠)。 I would like the default behaviour to be that the SideBar is not visible.我希望默认行为是 SideBar 不可见。

Does anyone have any suggestions on how to achieve this?有没有人对如何实现这一目标有任何建议?

Thanks,谢谢,

Andrew安德鲁

So it appears that the only way to come close to this (closing the sidebar when an NavLink is clicked in the sidebar) is to attach this to the NavigationView:所以看起来接近这个的唯一方法(在侧边栏中单击 NavLink 时关闭侧边栏)是将它附加到 NavigationView:

NavigationView {
   ...
}
 ..navigationViewStyle(StackNavigationViewStyle())

While this isn't quite what I was after, using this style I can use an Stack to establish a "Home" view to the right of the NavigationLinks to serve close the the purpose I had in mind.虽然这不是我所追求的,但使用这种样式,我可以使用 Stack 在 NavigationLinks 的右侧建立一个“主页”视图,以达到我的目的。

I hope that helps someone out there.我希望能帮助那里的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM