SwiftUI - 导航视图打开后退按钮和半灰屏/奇怪的行为 [英] SwiftUI - Navigation View opening with Back button and half grey screen / weird behavior

查看:42
本文介绍了SwiftUI - 导航视图打开后退按钮和半灰屏/奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的应用添加导航视图,但它导致了问题.我的主要用户界面是一个可无限滑动的页面轮播.它最初是这样的:

I am trying to add navigation view to my app, but it is causing issues. My main UI is an infinitely swipe-able carousel of pages. It originally looks like this:

然后当我将它包装在导航视图中时,它会像这样打开,只有一个后退按钮,没有别的:

Then when I wrap it in a navigation view, it opens like this, with a back button and nothing else:

当我按下后退按钮时,它看起来像这样:

When I hit the back button, it looks like this:

左侧像原始用户界面一样可以滑动,但是当我触摸右侧的灰色侧时,它会将我带回带有后退按钮的空白页面.

The left side is swipe-able like the original UI, but when I touch the right, grey side, it takes me back to the empty page with the back button.

知道是什么原因造成的吗?我通过将每个页面放在 ZStack 中并使用偏移量/相对位置来实现无限轮播.我参考了这个教程:https://www.youtube.com/watch?v=fB5MzDD1PZI

Any idea what may be causing this? I implemented the infinite carousel by putting each page in a ZStack, and using offsets/relativeLocation. I referred to this tutorial: https://www.youtube.com/watch?v=fB5MzDD1PZI

我可以不使用 NavigationView 吗?是否有替代路线可以让我创建自己的顶部 NavBar 并在没有 NavigationBar/NavigationLink 的情况下导航到单独的视图?

Can I not use a NavigationView? Is there an alternative route I can take in which I create my own top NavBar and navigate to separate views without NavigationBar/NavigationLink?

感谢任何帮助,请随时提出问题等.谢谢!

Any help is appreciated and please feel free to ask questions, etc. Thanks!

推荐答案

您想将 StackNavigationViewStyle 应用到您的 NavigationView.

You want to apply StackNavigationViewStyle to your NavigationView.

NavigationView {

...

}.navigationViewStyle(StackNavigationViewStyle())

您遇到了不需要的拆分视图,您可以在此处找到更多信息.

You're experiencing an unwanted split view, and you can find more info here.

对于横向的 iPad 或 iPhone Pro Max 等较大的设备,它默认为 DoubleColumnNavigationViewStyle.

For larger devices like an iPad or iPhone Pro Max in landscape, it defaults to DoubleColumnNavigationViewStyle.

这篇关于SwiftUI - 导航视图打开后退按钮和半灰屏/奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆