如何禁用NavigationStack推动动画
我希望立即出现的视图。而不是默认的iOS推动动画。
此方法使用与NavigationView
+ navigationLink
一起使用。 iOS 16弃用navigationView
enum Nav {
case a
}
struct ContentView: View {
@State var nav: [Nav] = []
var body: some View {
NavigationStack(path: $nav) {
Button {
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
nav = [.a] // Doesn't work. Still animates
}
} label: {
Text("Go to a")
}
.navigationDestination(for: Nav.self) { path in
switch path {
case .a:
Text("a")
}
}
}
}
}
I'd like the view to instantly appear. Instead of the default iOS push animation.
This method USED to work with a NavigationView
+ NavigationLink
. iOS 16 deprecated NavigationView
enum Nav {
case a
}
struct ContentView: View {
@State var nav: [Nav] = []
var body: some View {
NavigationStack(path: $nav) {
Button {
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
nav = [.a] // Doesn't work. Still animates
}
} label: {
Text("Go to a")
}
.navigationDestination(for: Nav.self) { path in
switch path {
case .a:
Text("a")
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是一个错误,值得向苹果提交反馈。
同时,这是可能的解决方法。用Xcode 14B2 / iOS测试16
This looks like a bug and worth submitting feedback to Apple.
Meanwhile here is a possible workaround. Tested with Xcode 14b2 / iOS 16