3
votes

When using TabView in SwiftUI, is it possible to modify the transitions between tab selection? Currently, when different tabs are selected, the transition is pretty sudden; actually instantaneously sudden, ouch.

For example, given the following:

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")
    }
}

How does one add something like .transition(AnyTransition.opacity.combined(with: .slide))

Thanks !

1

1 Answers

2
votes

You can add the .animation property to your TabView.

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

Basic animation types you have are .default, .easeIn, .easeOut, .easeInOut and .linear.

Hope this helps!