【问题标题】:SwiftUI animation tabs of a TabViewTabView 的 SwiftUI 动画选项卡
【发布时间】:2020-07-12 16:57:15
【问题描述】:

在 SwiftUI 中使用 TabView 时,是否可以修改选项卡选择之间的过渡? Currently, when different tabs are selected, the transition is pretty sudden;居然瞬间突然,哎哟。

例如,给定以下内容:

TabView {
Text("The First Tab")
    .tabItem {
        Image(systemName: "1.square.fill")
        Text("First")
    }
Text("Another Tab")
    .tabItem {
        Image(systemName: "2.square.fill")
        Text("Second")
    }
Text("The Last Tab")
    .tabItem {
        Image(systemName: "3.square.fill")
        Text("Third")
    }
}

如何添加类似 .transition(AnyTransition.opacity.combined(with: .slide)) 的东西

谢谢!

【问题讨论】:

    标签: animation swiftui transition


    【解决方案1】:

    您可以将 .animation 属性添加到您的 TabView。

    TabView {
       // code here
    }
    .animation(*animation type*)
    

    您拥有的基本动画类型是.default.easeIn.easeOut.easeInOut.linear

    希望这会有所帮助!

    【讨论】:

    • 我在 Xcode 选项卡式应用程序项目模板中尝试过。它不起作用。
    • @JustinNgan 有趣...在我的模板中也不起作用,但它确实适用于我现有的项目。将进一步调查。
    • 是的......虽然老实说,我发现 Swift 中的东西有时会做一些事情,但后来它不会。显然,它并不是只做它想做的事,而是发生了如此多的互动,以至于某个地方的一点点改变都会产生巨大的影响。如果你能在这方面取得任何进展,那就太棒了! ;-)
    猜你喜欢
    • 2020-01-05
    • 1970-01-01
    • 2021-05-18
    • 2020-12-03
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    相关资源
    最近更新 更多