i'm developing an app using swiftUI and i ran into some problems. Im trying to add an animation which will change scale and opacity as i'm dragging scrolling through pages in TabView which has PageTabViewStyle style. So as soon as the offset is changing when I'm dragging the page, so should the scale and opacity.The more I drag the page less opacity it has to have and the size has to be also changing.
I tried adding .gesture
modifier to the TabView with DragGesture()
. This worked but animation was executed only when pages already switched.
This is my code:
TabView(selection: $selection){
CardForSheetView()
.tag(0)
// .scaleEffect(selection == 0 ? 1 : max(0.1, 1 - abs(cardOffset / 200)))
// .opacity(selection == 0 ? 1 : max(0.1, 1 - abs(cardOffset / 200)))
CardForSheetView()
.tag(1)
// .scaleEffect(selection == 0 ? 1 : max(0.1, 1 - abs(cardOffset / 200)))
//.opacity(selection == 0 ? 1 : max(0.1, 1 - abs(cardOffset / 200)))
}
.tabViewStyle(PageTabViewStyle())
.frame( height: 300)
.onChange(of: selection) { newValue in
withAnimation (){
redOrBlue.toggle()
}
}
Pictures