I've tried this way, but actually it stops on a random point in the X-axis.
I really can't understand how to figure out this.
import SwiftUI
struct ContentView: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
let letters: [String] = ["A"]
@State private var xOffset: CGFloat = 0.0
@State private var yOffset: CGFloat = 0.0
@State var animation = false
var body: some View {
ForEach(letters, id: \.self) { letter in
Text(letter)
.padding()
.font(.largeTitle)
.offset(x: xOffset, y: yOffset)
.animation(Animation.linear(duration: 1.0).repeatForever(autoreverses: false))
.onAppear {
yOffset = CGFloat.random(in: 0...screenHeight)
}
}
Spacer()
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: