-
Notifications
You must be signed in to change notification settings - Fork 43
/
ScaleSpringAnimation.swift
48 lines (37 loc) · 1.17 KB
/
ScaleSpringAnimation.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
//
// ScaleSpringAnimation.swift
// Learning SwiftUI Spring Animations: The Basics and Beyond
//
// Created by Amos from getstream.io
//
import SwiftUI
struct ScaleSpringAnimation: View {
@State private var scaling = false
var body: some View {
VStack {
Text("Create a spring animation that bounces a ball into view by animating its scale from 1 to 2.")
.font(.title)
.multilineTextAlignment(.center)
Spacer()
Image("ball")
.scaleEffect(scaling ? 2 : 1)
.onAppear {
withAnimation(
.spring()
//.interactiveSpring()
.repeatForever(
autoreverses: false)) {
scaling.toggle()
}
}
Spacer()
}
.padding()
}
}
struct ScaleSpringAnimation_Previews: PreviewProvider {
static var previews: some View {
ScaleSpringAnimation()
.preferredColorScheme(.dark)
}
}