I have 3 Text View in a VStack, and I want the middle one to bounce by using scaleEffect. However, there is some additional unexpected up and down animation.
I found that once I remove the view from NavigationView, it will behave normal.
Is the problem on my side or Apple's side? And how to fix it? Thanks.
// TestingApp.swift
import SwiftUI
@main
struct TestingApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
LaunchView()
}
}
}
}
// LaunchView.swift
import SwiftUI
struct LaunchView: View {
var body: some View {
NavigationLink("To ContentView", destination: ContentView())
}
}
struct LaunchView_Previews: PreviewProvider {
static var previews: some View {
LaunchView()
}
}
// ContentView.swift
import SwiftUI
struct ContentView: View {
@State private var scaleFactor: CGFloat = 0.8
var body: some View {
VStack {
Text("Text above")
Text("Text bouncing")
.scaleEffect(scaleFactor)
.onAppear {
withAnimation(.spring().repeatForever(autoreverses: true)) {
scaleFactor = 1
}
}
Text("Text below")
}
.font(.largeTitle)
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}