如何禁用 NavigationView 推送和弹出动画 [英] How to disable NavigationView push and pop animations

查看:34
本文介绍了如何禁用 NavigationView 推送和弹出动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定这个简单的NavigationView:

struct ContentView : View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink("Push Me", destination: Text("PUSHED VIEW"))
            }
        }
    }
}

当目标视图被推入/弹出堆栈时,有没有人找到禁用 NavigationView 动画的方法?

Did anyone find a way of disabling the NavigationView animation when a destination view is pushed/popped into/from the stack?

从 iOS2.0 开始,这在 UIKit 中已经成为可能!我认为从框架中提出的要求并不过分.我在所有视图上尝试了各种修饰符(即 NavigationView 容器、​​目标视图、NavigationLink 等)

This has been possible in UIKit since iOS2.0! I think it is not too much to ask from the framework. I tried all sorts of modifiers on all views (i.e., the NavigationView container, the destination view, the NavigationLink, etc)

这些是我尝试过的一些修饰符:

These are some of the modifiers I tried:

.animation(nil)

.transition(.identity)

.transaction { t in t.disablesAnimations = true }

.transaction { t in t.animation = nil }

没有任何区别.我在 EnvironmentValues 中也没有发现任何有用的东西:-(

None made a difference. I did not find anything useful in the EnvironmentValues either :-(

我是否遗漏了一些非常明显的东西,或者功能还没有?

Am I missing something very obvious, or is the functionality just not there yet?

推荐答案

Xcode 11.3:

现在没有禁用 NavigationView 动画的修饰符.

Right now there is no modifier to disable NavigationView animations.

您可以使用结构 init() 来禁用动画,如下所示:

You can use your struct init() to disable animations, as below:

struct ContentView : View {

    init(){
        UINavigationBar.setAnimationsEnabled(false)
    }

    var body: some View {
        NavigationView {
            VStack {
                NavigationLink("Push Me", destination: Text("PUSHED VIEW"))
            }
        }
    }
}

这篇关于如何禁用 NavigationView 推送和弹出动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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