-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathTransformAndShapeMorphing.swift
38 lines (34 loc) · 1.15 KB
/
TransformAndShapeMorphing.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
//
// RectToRoundedRectToCircle.swift
// AnimateWithSprings
//
// Multi-step animation: A repeating animation that loops continuosly. Morph a rectangle to a rounded version and into a circle repeatedly. This uses chained animations.
//
import SwiftUI
enum RectAnimationPhase {
case start, middle, end
}
struct TransformAndShapeMorphing: View {
var body: some View {
Rectangle()
.fill(.blue.gradient)
.frame(width: 200, height: 200)
.phaseAnimator([RectAnimationPhase.start, .middle, .end], content: { view, phase in
view
.cornerRadius(phase == .start ? 0 :
phase == .middle ? 32 : 100)
.rotationEffect(.degrees(phase == .middle ? 180 : 0))
}, animation: { phase in
switch phase {
case .start: return .spring(duration: 1)
case .middle: return .spring(duration: 1)
case .end: return .spring(duration: 1)
}
})
}
}
// Preview remains the same
#Preview {
TransformAndShapeMorphing()
.preferredColorScheme(.dark)
}