WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.