Aben's Blog

vuePress-theme-reco Aben    2020 - 2025
Aben's Blog Aben's Blog

Choose mode

  • dark
  • auto
  • light
Home
Category
  • Docker
  • Node.js
  • golang
  • iOS
  • macOS
Tag
TimeLine
More
  • GitHub
  • Backend
author-avatar

Aben

21

Article

24

Tag

Home
Category
  • Docker
  • Node.js
  • golang
  • iOS
  • macOS
Tag
TimeLine
More
  • GitHub
  • Backend

Animation repeat forever when orientation changed

vuePress-theme-reco Aben    2020 - 2025

Animation repeat forever when orientation changed

Aben 2020-11-30 00:07:37 SwiftUIUserInterfaceSizeClassrepeatForeveranimation
...
    @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