1 Reply
      Latest reply on Sep 1, 2019 9:34 AM by literalPie
      yvsong Level 1 Level 1 (0 points)

        How to animate color changes with Color structure and Animatable protocol? AnimatableData supports floating point types only.

         

        (Edited.)

        • Re: Animate Color
          literalPie Level 1 Level 1 (0 points)

          If you are controlling the color with a State or something similar, all you need to do is make sure you change the state variable inside a withAnimation block.

           

          struct ColorView: View {
              @State var toggleable = true
              var body: some View {
                  VStack {
                      Text("Hello World")
                          .background(Color(toggleable ? UIColor.blue : UIColor.red))
                      Button(action: {
                          withAnimation {
                              self.toggleable.toggle()
                          }
                      }) {
                          Text("toggle")
                      }
                  }
              }
          }