【发布时间】:2022-12-27 13:16:31
【问题描述】:
I'm trying to create a TabView and it works fine, but I would like to animate the view change, but all I could find is to animate with the PageTabViewStyle, but it makes the screen draggable, which is something I don't want to. I think I could remove this gesture, but the tabView gets tiny, as the iOS Home Screen indicators.
So, basically I would like to change the animation between the Views, here's my current code:
struct MainView: View {
@State private var selectedTab = 0
private var pageTitles = ["Home", "Home2"]
var body: some View {
TabView(selection: $selectedTab) {
HomeView(test: .green)
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}.tag(0)
HomeView(test: .blue)
.tabItem {
Image(systemName: "house.fill")
Text("Home2")
}.tag(1)
}
.navigationTitle(Text(pageTitles[selectedTab]))
.navigationBarTitleDisplayMode(.inline)
}
}
【问题讨论】:
-
You can use a picker segmented control to select the visible view. So you can choose how you transition between view without swipe gestures.