简体   繁体   English

SwiftUI NavigationView/Stack 如果可用 iOS 15/16

[英]SwiftUI NavigationView/Stack if available iOS 15/16

There's something I don't really understand about the transition from NavigationView to NavigationStack for SwiftUI 4 and iOS 16.对于 SwiftUI 4 和 iOS 16 从NavigationViewNavigationStack的转换,我不太了解。

I have 2 applications running on the App Store (targeting iOS 15 and above) and of course I'm using NavigationView .我在 App Store 上运行了 2 个应用程序(针对 iOS 15 及更高版本),当然我正在使用NavigationView This weekend, I was looking for a solution to have them ready for iOS 16 by replacing:这个周末,我正在寻找一种解决方案,让他们为 iOS 16 做好准备,方法是替换:

var body: some View {
   NavigationView {
      ScrollView { /* code here */ }
   }
}

To something like this:对于这样的事情:

var body: some View {
   if #available(iOS 16, *) {
      NavigationStack {
   } else {
      NavigationView {
   }
      ScrollView { /* code here */ }
   }
}

But finally, before doing so, I tried them with iOS 16 Beta and they're perfectly fine.但最后,在这样做之前,我用 iOS 16 Beta 尝试了它们,它们非常好。 I don't understand, I thought it would be total a mess but finally no.我不明白,我以为它会完全一团糟,但最终没有。 Do you have an explanation?你有解释吗? Maybe, deprecated isn't what it should mean?也许,弃用不应该是什么意思?

NavigationView is deprecated , not obsoleted . NavigationView弃用,而不是过时 When a component becomes deprecated , it still can be used until Apple decides to obsolete it which will cause a crash when used.当一个组件被弃用时,它仍然可以使用,直到Apple决定废弃它,这会在使用时导致崩溃。 Although it's functional, you shouldn't use it.虽然它是功能性的,但你不应该使用它。

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

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