Animation repeat forever when orientation changed
...
@State private var lastSizeClass: UserInterfaceSizeClass?
@Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass?
...
var playButton: some View {
return ZStack {
Color
.white
.frame(width: 140, height: 100, alignment: .center)
.clipRounded(40.0)
.opacity(self.lastSizeClass == self.horizontalSizeClass ? 0 : 0.5)
.scaleEffect(self.lastSizeClass == self.horizontalSizeClass ? 1.2 : 0)
.animation(Animation
.easeOut(duration: 2)
.delay(2)
.repeatForever(autoreverses: false),
value: self.lastSizeClass)
.onAppear{
self.lastSizeClass = self.lastSizeClass == .compact ? .regular : .compact
}
...
}
}
...
var body: some View {
...
if horizontalSizeClass == .regular {
...
playButton
...
} else {
...
playButton
...
}
...
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
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