-
Notifications
You must be signed in to change notification settings - Fork 43
/
FallingBall.swift
51 lines (38 loc) · 1.23 KB
/
FallingBall.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// FallingBall.swift
// Learning SwiftUI Spring Animations: The Basics and Beyond
//
// Created by Amos from getstream.io
//
import SwiftUI
struct FallingBall: View {
@State private var moving = -60
var body: some View {
VStack {
Text("A ball falling with bounce")
.font(.title)
.multilineTextAlignment(.center)
Spacer()
ZStack {
Image("down")
Image("ball")
.offset(y: CGFloat(moving))
.onAppear(){
withAnimation(.spring(response: 0.25, dampingFraction: 0.3, blendDuration: 0).delay(1).repeatForever(autoreverses: false)){
moving = 10
}
}
Image("top")
.offset(x: 3)
}
.scaleEffect(2)
Spacer()
}
}
}
struct FallingBall_Previews: PreviewProvider {
static var previews: some View {
FallingBall()
.preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/)
}
}