Don't forget to provide a minimum reproducible example something we can copy and paste to ensure that the integrity if what you want is kept.
If your *StepView.count is static the code below might work for you
struct ButtonScroll: View {
@State var myId: Int = 0
init() {
//Add this
//It does NOT work with ScrollView
UIScrollView.appearance().isScrollEnabled = false
}
var body: some View {
VStack{
//Simulates myId changing
Button("change-position", action: {
myId = Int.random(in: 0...3)
print(myId.description)
})
ZStack{
//TabView does not allow for changes in Tab/Page count nicely
TabView(selection: $myId){
//Used Button to test interaction
Button("FirstStepView", action: {
print("FirstStepView")
}).tag(0)
Button("SecondStepView", action: {
print("SecondStepView")
}).tag(1)
Button("ThirdStepView", action: {
print("ThirdStepView")
}).tag(2)
Button("FourthStepView", action: {
print("FourthStepView")
}).tag(3)
}.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.animation(
Animation.easeOut(duration: 1)
)
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…