-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.swift
33 lines (29 loc) · 978 Bytes
/
Example.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
import SwiftUI
struct Example: View {
@State private var isWiggling = false
var body: some View {
VStack {
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(.blue)
.wiggling(isWiggling: $isWiggling, bounceAmount: 2, rotationAmount: 3)
// .wiggling(isWiggling: $isWiggling) we can also leave bounceAmount and rotationAmount blank, as the default values are 3 and 1 respectively
Button(action: {
withAnimation {
self.isWiggling.toggle()
}
}) {
Text(self.isWiggling ? "Disable Animation" : "Enable Animation")
}
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(10)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}