├── .swiftpm
└── xcode
│ ├── package.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ └── xcuserdata
│ │ └── philipdavis.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ └── philipdavis.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
├── Assets.xcassets
├── AccentColor.colorset
│ └── Contents.json
├── AppIcon.appiconset
│ └── Contents.json
└── Contents.json
├── ContentView.swift
├── MyApp.swift
├── Package.swift
└── README.md
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcuserdata/philipdavis.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/philipcdavis/swiftui-interpolated-spring-playground/16b3a4d9ac68d47deb9053c4cea4be23d1002542/.swiftpm/xcode/package.xcworkspace/xcuserdata/philipdavis.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/.swiftpm/xcode/xcuserdata/philipdavis.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | InterpolatedSpring.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "platform" : "ios",
6 | "size" : "1024x1024"
7 | }
8 | ],
9 | "info" : {
10 | "author" : "xcode",
11 | "version" : 1
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/ContentView.swift:
--------------------------------------------------------------------------------
1 | import SwiftUI
2 |
3 | struct ContentView: View {
4 | @State private var flag = true
5 | @State private var mass = 1.0
6 | @State private var stiffness = 104.0
7 | @State private var damping = 10.0
8 | @State private var initialVelocity = 5.0
9 | var body: some View {
10 | ZStack {
11 | Color(.black).ignoresSafeArea()
12 | VStack {
13 | ZStack {
14 | Color.white.opacity(0.2)
15 |
16 | ZStack {
17 | Color(.white)
18 | }
19 | .frame(width: 100, height: 100)
20 | .clipShape(RoundedRectangle(cornerRadius: 33, style: .continuous))
21 | .offset(x: 0, y: flag ? -100 : 100)
22 | }.onTapGesture() {
23 | withAnimation(.interpolatingSpring(mass: mass, stiffness: stiffness, damping: damping, initialVelocity: initialVelocity)) {
24 | flag.toggle()
25 | }
26 | }.clipShape(RoundedRectangle(cornerRadius: 24, style: .continuous))
27 | .padding()
28 |
29 |
30 | VStack() {
31 | VStack(alignment: .leading) {
32 |
33 | Text("Mass: \(Int(mass))")
34 | .foregroundColor(.white)
35 | Slider(
36 | value: $mass,
37 | in: 0...20
38 | )
39 | }
40 |
41 |
42 | VStack(alignment: .leading) {
43 | Text("Stiffness: \(Int(stiffness))")
44 | .foregroundColor(.white)
45 | Slider(
46 | value: $stiffness,
47 | in: 0...1000
48 | )
49 | }
50 |
51 | VStack(alignment: .leading) {
52 | Text("Damping \(Int(damping))")
53 | .foregroundColor(.white)
54 | Slider(
55 | value: $damping,
56 | in: 0...100
57 | )
58 |
59 | }
60 | VStack(alignment: .leading) {
61 | Text("Initial Velocity \(Int(initialVelocity))")
62 | .foregroundColor(.white)
63 | Slider(
64 | value: $initialVelocity,
65 | in: 0...100
66 | )
67 | }
68 |
69 | }.padding(20)
70 |
71 |
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/MyApp.swift:
--------------------------------------------------------------------------------
1 | import SwiftUI
2 |
3 | @main
4 | struct MyApp: App {
5 | var body: some Scene {
6 | WindowGroup {
7 | ContentView()
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version: 5.5
2 |
3 | // WARNING:
4 | // This file is automatically generated.
5 | // Do not edit it by hand because the contents will be replaced.
6 |
7 | import PackageDescription
8 | import AppleProductTypes
9 |
10 | let package = Package(
11 | name: "InterpolatedSpring",
12 | platforms: [
13 | .iOS("15.2")
14 | ],
15 | products: [
16 | .iOSApplication(
17 | name: "InterpolatedSpring",
18 | targets: ["AppModule"],
19 | bundleIdentifier: "com.philipcdavis.InterpolatedSpring",
20 | teamIdentifier: "X8UAQWJ2PH",
21 | displayVersion: "1.0",
22 | bundleVersion: "1",
23 | iconAssetName: "AppIcon",
24 | accentColorAssetName: "AccentColor",
25 | supportedDeviceFamilies: [
26 | .pad,
27 | .phone
28 | ],
29 | supportedInterfaceOrientations: [
30 | .portrait,
31 | .landscapeRight,
32 | .landscapeLeft,
33 | .portraitUpsideDown(.when(deviceFamilies: [.pad]))
34 | ]
35 | )
36 | ],
37 | targets: [
38 | .executableTarget(
39 | name: "AppModule",
40 | path: "."
41 | )
42 | ]
43 | )
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # swiftui-interpolated-spring-playground
2 |
3 | https://user-images.githubusercontent.com/3452573/164947928-9593f24e-8f80-44f5-8677-f4f225f3cbb4.MOV
4 |
--------------------------------------------------------------------------------