How can I hide my arrow text after ScrollView has scrolled?
struct Skroll: View {
var body: some View {
VStack(alignment: .trailing) {
Text("<-")
.font(.system(size: 25).bold())
.kerning(-3)
ScrollView(.horizontal, showsIndicators: false) {
HStack {
Rectangle()
.frame(width: 200, height: 300)
.cornerRadius(20)
Rectangle()
.frame(width: 200, height: 300)
.cornerRadius(20)
Rectangle()
.frame(width: 200, height: 300)
.cornerRadius(20)
}
}
}
.padding()
}
}
I can’t figure out how can I hide text after scrolling, I’m new and just learning SwiftUI
2
Answers
I think I figured out how to do it
result
I replaced my text with an image. I'm not sure if this is the right solution and I don't know if it might cause any errors, but this works for me. Maybe someone will find it useful too
Looks like what you need is to get the current position of the scroll view. See here on how to do that. Then you can choose to display
Text("<-")
based on a flag which is modified when ScollView reaches a certain pointIt might be also possible that you might achieve the same result by moving your
Text("<-")
inside the scroll view. See if below works for you