UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 45 (Project 9) Animation difficulties

Forums > 100 Days of SwiftUI

I could not get the trapezoid to animate as shown in the project (Animating simple shapes with animatableData). I am using Xcode Version 13.3 (13E113). To get it to work, I switched to the .animation(_ animation: Animation?, value: V) -> some View view modifier instead of the withAnimation { } function.

Trapezoid(insetAmount: insetAmount)
    .animation(.default, value: insetAmount)
    .frame(width: 200, height: 100)
    .onTapGesture {
        //withAnimation {
              insetAmount = Double.random(in: 10...90)
       //}
    }

Nothing in the definition of the Trapezoid Shape was changed from what was presented in Day 45. Again I solved it the same way as above. Interestingly, since both values (rows and columns) change together, and you can provide only one value to .animation(_ animation: Animation?, value: V) -> some View, it still works when you provide just one of the two values that change.

The same also happened with Checkerboard(Animating complex shapes with AnimatablePair).

Checkerboard(rows: rows, columns: columns)
    .animation(.default, value: rows)
    .onTapGesture {
        //withAnimation(.linear(duration: 3)) {
           rows = Int.random(in: 4...16)
           columns = Int.random(in: 4...16)
       //}
    }

I'd be interested to hear if anyone else is experiencing difficulties with this and how you solved them.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.